Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function reverseNumber(n) {
    let answer = 0;
    const temprary = (!isNaN(parseInt(n))) ? (n.toString().split('')): 0;
    //console.log(isNaN(parseInt(n)));
    //console.log(isNaN(parseInt(n)));
    //console.log(n.toString().split(''));
    //console.log(temprary);
    //console.log(typeof temprary);
    if (temprary.length > 0 && 'object' === typeof temprary ) {
      const numbers = (parseInt(n) >= 0) ? temprary : temprary.slice(1, temprary.length );
      const reverseNumbers = numbers.reverse().join(''); 
      //console.log(numbers);
      //console.log(reverseNumbers);
      answer = (parseInt(n) >= 0) ? +reverseNumbers: -1*(+reverseNumbers);
    }
    return answer;
}

console.log(reverseNumber(123));
console.log(reverseNumber(-123));
console.log(reverseNumber(1000));
console.log(reverseNumber(4321234));
console.log(reverseNumber(5));
console.log(reverseNumber(0));
console.log(reverseNumber(98989898));
node v9.7.1 linux/amd64