Created
June 11, 2020 15:50
-
-
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]
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
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