JavaScript/4kyu/ParseInt_reloaded.js
// All tested numbers are valid, you don't need to validate them
All tested numbers are valid, you don't need to validate them
All tested numbers are valid you don ' t need to validate them
function parseInt(string) {
  let small = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5,
    'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'ten': 10,
    'eleven': 11, 'twelve': 12, 'thirteen': 13, 'fourteen': 14, 'fifteen': 15,
    'sixteen': 16, 'seventeen': 17, 'eighteen': 18, 'nineteen': 19, 'twenty': 20,
    'thirty': 30, 'forty': 40, 'fifty': 50, 'sixty': 60, 'seventy': 70,
    'eighty': 80, 'ninety': 90
  } 
  let large = {'thousand': 1000, 'million': 1000000 }
  let array = string.split(/[\s-]+/);
  let n = 0;
  let g = 0;
  for (let i = 0; i < array.length; i++) {
    let word = array[i];
    if (small[word]) {
      g = g + small[word];
    } else if (word === "hundred") {
      g = g * 100;
    } else {
      if (large[word]) {
        n = n + g * large[word];
        g = 0;
      }
    }
  }
  return n + g;
}
function parseInt ( string ) { let small = { 'zero' : 0 , 'one' : 1 , 'two' : 2 , 'three' : 3 , 'four' : 4 , 'five' : 5 , 'six' : 6 , 'seven' : 7 , 'eight' : 8 , 'nine' : 9 , 'ten' : 10 , 'eleven' : 11 , 'twelve' : 12 , 'thirteen' : 13 , 'fourteen' : 14 , 'fifteen' : 15 , 'sixteen' : 16 , 'seventeen' : 17 , 'eighteen' : 18 , 'nineteen' : 19 , 'twenty' : 20 , 'thirty' : 30 , 'forty' : 40 , 'fifty' : 50 , 'sixty' : 60 , 'seventy' : 70 , 'eighty' : 80 , 'ninety' : 90 } let large = { 'thousand' : 1000 , 'million' : 1000000 } let array = string . split ( / [\s-]+ / ) ; let n = 0 ; let g = 0 ; for ( let i = 0 ; i < array . length ; i ++ ) { let word = array [ i ] ; if ( small [ word ] ) { g = g + small [ word ] ; } else if ( word === "hundred" ) { g = g * 100 ; } else { if ( large [ word ] ) { n = n + g * large [ word ] ; g = 0 ; } } } return n + g ; }
All tested numbers are valid, you don't need to validate them
All tested numbers are valid you don ' t need to validate them