Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Created March 15, 2015 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanseys/43e8eb4f234fd0a5a03c to your computer and use it in GitHub Desktop.
Save ryanseys/43e8eb4f234fd0a5a03c to your computer and use it in GitHub Desktop.
Reverse the numbers after decimal in list of numbers
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