Skip to content

Instantly share code, notes, and snippets.

@elisavetTriant
Created July 18, 2019 19:40
Show Gist options
  • Save elisavetTriant/fbdd9e299dcb5f80fd865ae17068a4ec to your computer and use it in GitHub Desktop.
Save elisavetTriant/fbdd9e299dcb5f80fd865ae17068a4ec to your computer and use it in GitHub Desktop.
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