Created
September 25, 2021 10:25
-
-
Save Stefanacef/0dfbf89124dd5b7f0bee560dfe25ed77 to your computer and use it in GitHub Desktop.
Integer Reversal Solution | JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Integer Reversal | |
const number=123456; | |
const rev = function (num) { | |
const numRev = number | |
.toString() | |
.split("") | |
.reverse() | |
.join(""); | |
return parseInt(numRev); | |
}; | |
console.log(rev(number)); | |
////////////OR | |
const num =number.toString().split('').reduce((acc,val)=>{ | |
return acc=val+acc | |
},'') | |
console.log(num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment