Skip to content

Instantly share code, notes, and snippets.

@Gosilama
Created June 11, 2020 15:50
Show Gist options
  • Save Gosilama/0e9ead6e5aad35b44a86c147232776a4 to your computer and use it in GitHub Desktop.
Save Gosilama/0e9ead6e5aad35b44a86c147232776a4 to your computer and use it in GitHub Desktop.
Write a function that converts number to text, Passing an int number should return array of text number eg 23498643 => [two, three, four, nine, eight, six, four, three] 40263645 => [four, zero, two, six, three, six, four, four, five]
const ds = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
const getNumStringArr = (num) => {
const numArr = num.toString().split('');
const resultArr = [];
for (let i = 0; i < numArr.length; i++) {
const m = parseInt(numArr[i]);
resultArr.push(ds[m]);
}
return resultArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment