I want to know how to reverse the order of the numbers, yet keep the minus sign(-) at its place. See the code below to get what i mean.
The idea this challenge is to reverse the number, and then to check if the reversed version of the number is less than -2 ^ 31 or if it’s bigger than 2 ^ 31 - 1. Then i should return 0, otherwise, i should return the reversed version of the number.
const reverse = x => {
const array = x.toString().split("");
const newArray = [];
for (let B = array.length - 1; B >= 0; B = B - 1) {
if (typeof array[B] === "number") {
newArray.push(array[B]);
return newArray;
} else {
array[B];
}}
};
// the numbers in the comments are the desired result.
console.log(reverse(0)); // 0
console.log(reverse(120)); // 21
console.log(reverse(123)); // 321
console.log(reverse(-123)); // -321
console.log(reverse(1534236469)); // 0