Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = [
- '290',
- ];
- let p = console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let numberStr = gets();
- let len = numberStr.length;
- let unitsObj = {
- '0': 'zero',
- '1': 'one',
- '2': 'two',
- '3': 'three',
- '4': 'four',
- '5': 'five',
- '6': 'six',
- '7': 'seven',
- '8': 'eight',
- '9': 'nine',
- };
- let dozensObj = {
- '10': 'ten',
- '20': 'twenty',
- '30': 'thirty',
- '40': 'forty',
- '50': 'fifty',
- '60': 'sixty',
- '70': 'seventy',
- '80': 'eighty',
- '90': 'ninety',
- };
- let numbers10to19 = {
- '10': 'ten',
- '11': 'eleven',
- '12': 'twelve',
- '13': 'thirteen',
- '14': 'fourteen',
- '15': 'fifteen',
- '16': 'sixteen',
- '17': 'seventeen',
- '18': 'eighteen',
- '19': 'nineteen',
- };
- if (len == 3) {
- if (numberStr[2] === '0' && numberStr[1] === '0') {
- p(`${unitsObj[numberStr[0]]} hundred`);
- } else if (numberStr[1] === '0') {
- p(`${unitsObj[numberStr[0]]} hundred and ${unitsObj[numberStr[2]]}`);
- } else if (numberStr[2] === '0') {
- if (numberStr[1] === '1') {
- p(`${unitsObj[numberStr[0]]} hundred and ten`);
- } else {
- p(`${unitsObj[numberStr[0]]} hundred and ${dozensObj[numberStr[1] + '0']}`);
- }
- } else {
- if (numberStr[1] === '1') {
- p(`${unitsObj[numberStr[0]]} hundred and ${numbers10to19['1' + numberStr[2].toString()]}`);
- } else {
- p(`${unitsObj[numberStr[0]]} hundred and ${dozensObj[numberStr[1] +
- '0']} ${unitsObj[numberStr[2]]}`);
- }
- }
- } else if (len === 2) {
- if (numberStr[1] === '0') {
- p(`${dozensObj[numberStr[0] + '0']}`);
- } else if (numberStr[0] === '1') {
- p(`${numbers10to19['1' + numberStr[1].toString()]}`);
- } else {
- p(`${dozensObj[numberStr[0] + '0']} ${unitsObj[numberStr[1]]}`);
- }
- } else {
- p(`${unitsObj[numberStr[0]]}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement