Created
March 15, 2015 17:41
-
-
Save ryanseys/43e8eb4f234fd0a5a03c to your computer and use it in GitHub Desktop.
Reverse the numbers after decimal in list of numbers
This file contains hidden or 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
function reverseDecimal(num) { | |
var arr = num.toString().split('.'); | |
arr[1] = arr[1].split('').reverse().join(''); | |
return parseFloat(arr.join('.')); | |
} | |
var numbers = [0.24, 0.35, 0.76]; | |
console.log(numbers.map(reverseDecimal)); | |
// Example: [ 0.12, 0.34, 0.56 ] --> [ 0.21, 0.43, 0.65 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment