From d39e9fb6cf90f3939d9661535a410d69307560c2 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Wed, 15 Jul 2020 18:57:54 -0500 Subject: [PATCH 1/8] YAY --- main.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index 1c92f304..071cb892 100644 --- a/main.js +++ b/main.js @@ -11,12 +11,71 @@ const rl = readline.createInterface({ }); -const pigLatin = (word) => { - // Your code here + + +// ********** +// HINTS +// ********** + +// break your code into pieces and focus on one piece at a time... +// 1. if word begins with a vowel send to one function: adds "yay" +// 2. if word begins in with a consonant send to another function: splices off beginning, returns word with new ending. +// 3. if multiple words, create array of words, loop over them, sending them to different functions and creating a new array with the new words. + + +// "yesTerday" => esterdayyay +// scrub the data +// if word begins with vowel add 'yay' +// turn our string into an array + + +// if word begins with consonant +// list the vowels: a, e, i, o, u +// run through string until we find the first vowel +// identify index position, store and use +// store sound before vowel in a variable (bucket) + + +// splice out 'y' (first sound) +// concat/push 'y' (first sound) to end + + +// concat 'ay' to the end + +let vowelArray = ['a', 'e', 'i', 'o', 'u'] + + + + +const findWord = () => { } + +const pigLatin = (word) => { + let splitWord = word.trim().toLowerCase().split('') + let yay = "yay" + const addYay = () => { + return word.concat(yay) + } + for(let i = 0; i < splitWord.length; i++) { + if (vowelArray.includes(splitWord)) { + addYay(); + } else { + findWord(); + } + } + + return addYay() + +} + + + + + + // 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 @@ -57,15 +116,3 @@ if (typeof describe === 'function') { } - - - - -// ********** -// HINTS -// ********** - -// break your code into pieces and focus on one piece at a time... -// 1. if word begins with a vowel send to one function: adds "yay" -// 2. if word begins in with a consonant send to another function: splices off beginning, returns word with new ending. -// 3. if multiple words, create array of words, loop over them, sending them to different functions and creating a new array with the new words. \ No newline at end of file From 4a310cad8cd6f51ff517d2761099db9cc72a5c08 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 03:04:10 -0500 Subject: [PATCH 2/8] semi-breakthrough --- main.js | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/main.js b/main.js index 071cb892..d9577820 100644 --- a/main.js +++ b/main.js @@ -23,53 +23,46 @@ const rl = readline.createInterface({ // 2. if word begins in with a consonant send to another function: splices off beginning, returns word with new ending. // 3. if multiple words, create array of words, loop over them, sending them to different functions and creating a new array with the new words. - // "yesTerday" => esterdayyay -// scrub the data -// if word begins with vowel add 'yay' -// turn our string into an array // if word begins with consonant -// list the vowels: a, e, i, o, u // run through string until we find the first vowel // identify index position, store and use // store sound before vowel in a variable (bucket) - // splice out 'y' (first sound) // concat/push 'y' (first sound) to end - // concat 'ay' to the end -let vowelArray = ['a', 'e', 'i', 'o', 'u'] - - - - -const findWord = () => { - -} - - const pigLatin = (word) => { - let splitWord = word.trim().toLowerCase().split('') - let yay = "yay" - const addYay = () => { - return word.concat(yay) + let splitWord = word.trim().toLowerCase().split('') + const vowelArray = ['a', 'e', 'i', 'o', 'u'] + for(let i = 0; i < splitWord.length; i++) { + if (vowelArray.includes(splitWord[0])) { + return word.concat("yay"); + } else { + findFirstVowel(); + } + } } - for(let i = 0; i < splitWord.length; i++) { - if (vowelArray.includes(splitWord)) { - addYay(); - } else { - findWord(); + + const findFirstVowel = (firstVowel) => { + for(let i = 0; i < splitWord.length; i++) { + if (splitWord[i].includes(vowelArray)) { + return splitWord.search(vowelArray) + } else { + + } } + } return addYay() -} + + From 3c81a2edd1684257f35d251301eb79b5d9f3f92d Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 04:11:35 -0500 Subject: [PATCH 3/8] let it be --- main.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index d9577820..75ca1e9f 100644 --- a/main.js +++ b/main.js @@ -36,30 +36,38 @@ const rl = readline.createInterface({ // concat 'ay' to the end + +const vowelArray = ['a', 'e', 'i', 'o', 'u'] + const pigLatin = (word) => { let splitWord = word.trim().toLowerCase().split('') - const vowelArray = ['a', 'e', 'i', 'o', 'u'] - for(let i = 0; i < splitWord.length; i++) { - if (vowelArray.includes(splitWord[0])) { - return word.concat("yay"); - } else { - findFirstVowel(); - } - } + for(let i = 0; i < splitWord.length; i++) { + if (vowelArray.includes(splitWord[0])) { + return word.concat("yay"); + } else { + return findFirstVowel(splitWord); + } } + + +} - const findFirstVowel = (firstVowel) => { - for(let i = 0; i < splitWord.length; i++) { - if (splitWord[i].includes(vowelArray)) { - return splitWord.search(vowelArray) - } else { +const findFirstVowel = (consonantWord) => { + let foundVowel = + for(let i = 0; i < vowelArray.length; i++) { + if (splitWord.includes(vowelArray[i])) { + return splitWord.search(vowelArray.join()); + // modifyWord() - } + // } + // else { + + // } } } +} - return addYay() From 4321e8d1bdc51c463e3fc443a6dd2b7dc5ea13a0 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 04:13:04 -0500 Subject: [PATCH 4/8] turn-in commit --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 75ca1e9f..1fbeab05 100644 --- a/main.js +++ b/main.js @@ -34,7 +34,7 @@ const rl = readline.createInterface({ // splice out 'y' (first sound) // concat/push 'y' (first sound) to end -// concat 'ay' to the end +// concat 'ay' to the end const vowelArray = ['a', 'e', 'i', 'o', 'u'] From 1263c4577ca72b85625de3b7698ddc678e32b10a Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 05:08:36 -0500 Subject: [PATCH 5/8] this seems significant --- main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 1fbeab05..a6335420 100644 --- a/main.js +++ b/main.js @@ -53,10 +53,11 @@ const pigLatin = (word) => { } const findFirstVowel = (consonantWord) => { - let foundVowel = + let poop = consonantWord.join() for(let i = 0; i < vowelArray.length; i++) { - if (splitWord.includes(vowelArray[i])) { - return splitWord.search(vowelArray.join()); + if (poop.includes(vowelArray[i])) { + return poop.search(vowelArray.join()); + // modifyWord() // } From 0224351b2d5953e930ce8a6b652df28321945199 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 05:15:57 -0500 Subject: [PATCH 6/8] black magic is afoot --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index a6335420..72c5a581 100644 --- a/main.js +++ b/main.js @@ -56,7 +56,7 @@ const findFirstVowel = (consonantWord) => { let poop = consonantWord.join() for(let i = 0; i < vowelArray.length; i++) { if (poop.includes(vowelArray[i])) { - return poop.search(vowelArray.join()); + return poop.match(vowelArray[i]); // modifyWord() From a6cf0afe197413771a1e4960c9b5411a8fb08126 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 23:52:35 -0500 Subject: [PATCH 7/8] damn destiny and ariel... that's some fine code... --- main.js | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/main.js b/main.js index 72c5a581..4c87017d 100644 --- a/main.js +++ b/main.js @@ -37,37 +37,23 @@ const rl = readline.createInterface({ // concat 'ay' to the end -const vowelArray = ['a', 'e', 'i', 'o', 'u'] - -const pigLatin = (word) => { - let splitWord = word.trim().toLowerCase().split('') - for(let i = 0; i < splitWord.length; i++) { - if (vowelArray.includes(splitWord[0])) { - return word.concat("yay"); - } else { - return findFirstVowel(splitWord); - } +const pigLatin = (word) => { + let vowels = ['a', 'e', 'i', 'o', 'u']; + let finalWord = ""; + let cleanWord = word.toLowerCase().trim() + if (vowels.indexOf(cleanWord[0]) > -1) { + finalWord = cleanWord + "yay"; + return finalWord; + } else { + // we used a regex BOOM + let firstMatch = cleanWord.match(/[aeiou]/g) || 0; + let vowelIndex = cleanWord.indexOf(firstMatch[0]); + finalWord = cleanWord.slice(vowelIndex) + cleanWord.slice(0, vowelIndex) + "ay"; + return finalWord; } - - } - -const findFirstVowel = (consonantWord) => { - let poop = consonantWord.join() - for(let i = 0; i < vowelArray.length; i++) { - if (poop.includes(vowelArray[i])) { - return poop.match(vowelArray[i]); - - // modifyWord() - // } - // else { - // } - } - - } -} From 2ff8b4d172c5b10f5c43f19eb467782bd138353f Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Mon, 20 Jul 2020 03:19:13 -0500 Subject: [PATCH 8/8] i may not have wrote it, but i stared at it for like 5 hrs --- main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 4c87017d..a589d3ce 100644 --- a/main.js +++ b/main.js @@ -42,10 +42,9 @@ const pigLatin = (word) => { let finalWord = ""; let cleanWord = word.toLowerCase().trim() if (vowels.indexOf(cleanWord[0]) > -1) { - finalWord = cleanWord + "yay"; - return finalWord; + finalWord = cleanWord + "yay"; + return finalWord; } else { - // we used a regex BOOM let firstMatch = cleanWord.match(/[aeiou]/g) || 0; let vowelIndex = cleanWord.indexOf(firstMatch[0]); finalWord = cleanWord.slice(vowelIndex) + cleanWord.slice(0, vowelIndex) + "ay";