Skip to content

Instantly share code, notes, and snippets.

@cb1kenobi
Created March 28, 2016 05:20
Show Gist options
  • Save cb1kenobi/2b162eaafee34d44ea53 to your computer and use it in GitHub Desktop.
Save cb1kenobi/2b162eaafee34d44ea53 to your computer and use it in GitHub Desktop.
Numbers to words
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