“Reverse Integer di JavaScript” Kode Jawaban

Nomor terbalik JavaScript

// 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
Kaotik

cara membalikkan nomor dalam javascript

// how to reverse number in javascript
let number = 12345;
let reverse = parseInt(number.toString().split('').reverse().join(''));
console.log(reverse);
// Output:
// 54321
Chetan Nada

Membalikkan angka dalam javascript

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);
Information Technology Enthusiast

Reverse Int JS

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;
}
Fylls

Reverse Integer di JavaScript

/**
 * @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
    
};
Filthy Falcon

Reverse Int JS

function reverseInt(n) {
  const reversed = n.toString().split("").reverse().join(""); 

  return parseInt(reversed) * Math.sign(n);
}
Wandering Whale

Jawaban yang mirip dengan “Reverse Integer di JavaScript”

Pertanyaan yang mirip dengan “Reverse Integer di JavaScript”

Lebih banyak jawaban terkait untuk “Reverse Integer di JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya