Skip to content

Instantly share code, notes, and snippets.

@umair-khanzada
Last active November 13, 2016 13:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umair-khanzada/614f4ee202b6f1337bd0b2fd8e68cbf9 to your computer and use it in GitHub Desktop.
Save umair-khanzada/614f4ee202b6f1337bd0b2fd8e68cbf9 to your computer and use it in GitHub Desktop.
let lsb = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'saven', 'eight', 'nine'],
mid = ['', 'ten', 'tweenty', 'therty', 'fourty', 'fifty', 'sixty', 'saventy', 'eighty', 'ninty'],
msb = ['', 'one hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred', 'six hundred', 'saven hundred', 'eight hundred', 'nine hundred'],
num = 445;
input = String(num);
let msbBit = Number(input[0]),
midBit = input.length > 1 ? Number(input[1]) : 0,
lsbBit = input.length > 2 ? Number(input[2]) : 0;
let result = `${msb[msbBit]} ${mid[midBit]} ${lsb[lsbBit]}`;
//result "four hundred fourty five"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment