// Function to reverse Number
function reverseNum(n) {
let r = n.toString().split('').reverse().join('');
return Math.sign(n) * parseInt(r);
}
// Call
reverseNum(-267);
reverseNum(31522);
// Outputs
-762
22513
// how to reverse number in javascript
let number = 12345;
let reverse = parseInt(number.toString().split('').reverse().join(''));
console.log(reverse);
// Output:
// 54321
let rev = 0;
let num = 123456;
let lastDigit;
while(num != 0){
lastDigit = num % 10;
rev = rev * 10 + lastDigit;
num = Math.floor(num/10);
}
console.log("Reverse number : "+rev);
function reverseInt(n) {
let reversed = n.toString().split("").reverse().join("");
//from string to integer
reversed = parseInt(reversed);
if (n < 0) {
return reversed * -1;
}
return reversed;
}
const num = 3849;
function reverseGivenInteger(num) {
return Number(String(num).split('').reverse().join(''))
}
console.log(`Reversed integer is: ${reverseGivenInteger(num)}`)
/**
* @param {number} x
* @return {number}
*/
var reverse = function(x) {
x = x + '';
let reversedStr = x.split('').reverse().join('');
if(reversedStr.includes('-')) {
reversedStr = reversedStr.split('-')[0]
reversedStr = '-'+reversedStr
}
if(2147483647 < reversedStr || -2147483648 > reversedStr) {
return 0
}
return reversedStr
};
function reverseInt(n) {
const reversed = n.toString().split("").reverse().join("");
return parseInt(reversed) * Math.sign(n);
}
const reversedNum = num => parseFloat(num.toString().split('').reverse().join('')) * Math.sign(num)
var text = ""
var i = 0
var array = ["1", "2", "3"]
var number = array.length
var arrayFinal = []
for (i = 0; i < array.length; i++) {
text = array[number - 1]
arrayFinal.push(text)
text = ""
number = number - 1
}
console.log(arrayFinal)