0215 / Problem solving for the day!
How the reverse an array?
const reverse = x => { // arrow function expression
let stringX = x.toString(); // X.toString() method, which represents the value of the number of the Number Object using the primitive data type value is returned
let arrayX = [];
for (let i = 0; i < stringX.length; i++) {
// for loop iterates, over keys and
returns the length of a string into a loop
arrayX.unshift(stringX.charAt(i));
// set method so that charAt can return character of an [I] index of array, one elements to the beginning of an array to return the new length of the array.
}
// If the method takes two arguments, the a string representation of the first argument in the radix specified by the second argument will be returned.
if(x < 0) {.
arrayX.splice(-1,1); // splice() method changes the contents of Ana array by removing .
arrayX.unshift(“-”); minus position will return to the front
}
const restringX = arrayX.join(“”); // concatenating in an array
return Number(restringX); // will return the number(array)
}
module.exports = { reverse };