Q. Convert number to reversed array of digits
Given a random non-negative number, you have to return the digits of this number within an array in reverse order.
Example(Input => Output):
348597 => [7,9,5,8,4,3]
0 => [0]
function digitize(n) {
return String(n).split("").reverse().map(Number);
}
- String(num)
The String global object acts as a constructor for strings and "converts" the given number into string(in this case)- The Array.reverse()
method reverses an array in place- The Array.map()
method creates and returns a new array calling a
provided function on every array element