Created
July 18, 2019 19:40
-
-
Save elisavetTriant/fbdd9e299dcb5f80fd865ae17068a4ec to your computer and use it in GitHub Desktop.
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
function convertNumberToUnits(n) { | |
let numberToBreakUp = n.toString(); | |
let unitsArray = numberToBreakUp.split(""); | |
return unitsArray.map((item, index, array) => { | |
let zeros = '0'.repeat(array.length - index - 1); | |
return parseInt(item.concat(zeros), 10); | |
} | |
); | |
} | |
convertNumberToUnits(1259); | |
/*returns an array in the form: [1000, 200, 50, 9] */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment