From 853b016bb330f8aaf1cf36d34fcaf41934422f23 Mon Sep 17 00:00:00 2001 From: Stanley M Musial <68257825+StanleyMMusial@users.noreply.github.com> Date: Wed, 11 Nov 2020 12:55:00 -0600 Subject: [PATCH 1/2] Finished --- main.js | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 1c92f304..735cfb4b 100644 --- a/main.js +++ b/main.js @@ -13,10 +13,42 @@ const rl = readline.createInterface({ const pigLatin = (word) => { - // Your code here + word = word.trim() + word = word.toLowerCase() + const isVowel = ['a','e','i','o','u'] -} + let wordSplitter = word.split('') + + let firstLetter = wordSplitter[0] + + console.log(firstLetter) + + if (isVowel.includes(firstLetter)) { + let pigLatinWord = word + 'yay' + return pigLatinWord + } + + for(let i = 0; i < wordSplitter.length ; i++) { + let letter = wordSplitter[i] + if (isVowel.includes(letter)) { + // grab all the letters smaller than i; + const consonants = wordSplitter.splice(0, i) + // const consonants = ['c', 'h'] + // 0 1 2 + // split: ['e', 'a', 't'] + wordSplitter.splice(wordSplitter.length, 0, ...consonants) + // split: ['e', 'a', 't', 'c', 'h'] + let finishedWord = wordSplitter.join('') + 'ay' + // let pigLatinConsonant = split + consonants + 'ay' + return finishedWord + } + } + + + + +} // the first function called in the program to get an input from the user // to run the function use the command: node main.js // to close it ctrl + C From c030ef5a7b78bdd4f0078c7eb303e4460f572136 Mon Sep 17 00:00:00 2001 From: Stanley M Musial <68257825+StanleyMMusial@users.noreply.github.com> Date: Wed, 11 Nov 2020 14:58:45 -0600 Subject: [PATCH 2/2] Added comments --- main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 735cfb4b..7869c6df 100644 --- a/main.js +++ b/main.js @@ -10,18 +10,20 @@ const rl = readline.createInterface({ output: process.stdout }); - +// main function const pigLatin = (word) => { word = word.trim() word = word.toLowerCase() const isVowel = ['a','e','i','o','u'] + // splitting the input word for better use of the loop let wordSplitter = word.split('') let firstLetter = wordSplitter[0] console.log(firstLetter) + // checking if the first letter is indeed a vowel if (isVowel.includes(firstLetter)) { let pigLatinWord = word + 'yay'