Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.