// Pseudocode
// Input: an integer
// Output: a string representing the integer in English
// Create a blank string
// Take in an integer and split it into three number long collection objects
// IF the number is smaller than three places, split it into a three-number collection object with zeroes for any missing digits
// FOR each three-number chunk
// Check the hundreds place against the words list and add it to the blank string with the word for hundreds
// Check the tens place against the words list and add it to the blank string
// Check the ones list against the words list and add it to the blank string
// Return the string

var WORDS = {
  1: "one",
  2: "two",
  3: "three",
  4: "four",
  5: "five",
  6: "six",
  7: "seven",
  8: "eight",
  9: "nine",
  10: "ten",
  11: "eleven",
  12: "twelve",
  13: "thirteen",
  14: "fourteen",
  15: "fifteen",
  16: "sixteen",
  17: "seventeen",
  18: "eighteen",
  19: "nineteen",
  20: "twenty",
  30: "thirty",
  40: "forty",
  50: "fifty",
  60: "sixty",
  70: "seventy",
  80: "eighty",
  90: "ninety",
};

function in_words(num){
  if (num.toString().length == 1){
    return WORDS[num];
  }
  else if (num.toString().length == 2 && num <= 20){
    return WORDS[num];
  }
  else {
    num_array = num.toString().split("");
    if (num_array.length == 2){
      return WORDS[num_array.shift() + "0"] + " " + in_words(num_array.join(""));
    }
    if (num_array.length == 3){
      return WORDS[num_array.shift()] + " hundred " + in_words(num_array.join(""));
    }
    if (num_array.length == 4){
      return WORDS[num_array.shift()] + " thousand " + in_words(num_array.join(""));
    }
  }
}



console.log(in_words(4));
console.log(in_words(19));
console.log(in_words(27));
console.log(in_words(92));
console.log(in_words(112));
console.log(in_words(347));
console.log(in_words(999));
console.log(in_words(3342));

@@ -1063,16 +1063,693 @@
 y%22,%0A%7D;%0A%0A
+// function in_words(num)%7B%0A//   if (num.toString().length == 1)%7B%0A//     return WORDS%5Bnum%5D;%0A//   %7D%0A//   else if (num.toString().length == 2 && num %3C= 20)%7B%0A//     return WORDS%5Bnum%5D;%0A//   %7D%0A//   else %7B%0A//     var num_array = num.toString().split(%22%22);%0A//     if (num_array.length == 2)%7B%0A//       return WORDS%5Bnum_array.shift() + %220%22%5D + %22 %22 + in_words(num_array.join(%22%22));%0A//     %7D%0A//     if (num_array.length == 3)%7B%0A//       return WORDS%5Bnum_array.shift()%5D + %22 hundred %22 + in_words(num_array.join(%22%22));%0A//     %7D%0A//     if (num_array.length == 4)%7B%0A//       return WORDS%5Bnum_array.shift()%5D + %22 thousand %22 + in_words(num_array.join(%22%22));%0A//     %7D%0A//   %7D%0A// %7D%0A%0A// Refactored solution%0A%0A
 function
@@ -1919,16 +1919,75 @@
 e %7B%0A    
+var special_words = %5B,,,%22 hundred %22,%22 thousand %22%5D;%0A    var 
 num_arra
@@ -2144,34 +2144,12 @@
     
-if (num_array.length == 3)
+else
 %7B%0A  
@@ -2190,142 +2190,43 @@
 %5D + 
-%22 hundred %22 + in_words(num_array.join(%22%22));%0A    %7D%0A    if (num_array.length == 4)%7B%0A      return WORDS%5Bnum_array.shift()%5D + %22 thousand %22
+special_words%5Bnum_array.length + 1%5D
  + i
@@ -2267,16 +2267,30 @@
 %0A  %7D%0A%7D%0A%0A
+// Driver Code
 %0A%0Aconsol
@@ -2499,12 +2499,307 @@
 rds(3342));%0A
+%0A// Reflection%0A// - What concepts did you solidify in working on this challenge?%0A%0A// - What was the most difficult part of this challenge?%0A%0A// - Did you solve the problem in a new way this time?%0A%0A// - Was your pseudocode different from the Ruby version? What was the same and what was different?

Add refactored solution.