Created
March 28, 2016 05:20
-
-
Save cb1kenobi/2b162eaafee34d44ea53 to your computer and use it in GitHub Desktop.
Numbers to words
This file contains hidden or 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 lookup = { | |
zero: 0, | |
one: 1, | |
two: 2, | |
three: 3, | |
four: 4, | |
five: 5, | |
six: 6, | |
seven: 7, | |
eight: 8, | |
nine: 9 | |
}; | |
function numToString(str) { | |
return str.replace(/(\w+);/g, (s, m) => lookup[m]); | |
} | |
console.log(numToString('one;two;three;four;')); | |
console.log(numToString('eight;three;two;one;seven;')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment