From 279faf81866a9f8acacf80dd1716e18be077015d Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 1 Feb 2018 20:50:55 -0600 Subject: [PATCH 1/2] initial commit --- 02week/pigLatin.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 046434c94..0b736fe79 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -6,14 +6,28 @@ const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); +/* I need at least two more functions to meet the benchmarks for this assignment. I will probably complete this and then find out there's a bunch of bugs and a way easier way, but leggo. */ +/*Based on the tests, I need at least three functions. One of which will probably be specifically to address the vowel test. Would probably be best to use an if statement to look for vowels at the beginning of my chosen word, or in this case, a bunch of string. IF the word matches the criteria, then I will have it return the word+way. */ +/* For any other words, it seems intuitive just to use a function that moves the first letter to the end of the word (maybe using an array method?) and then adding ay.*/ +/* The first function below splits the word or string into an array of substrings, which allows the following functions to move letters (which now make up the new array) around. */ +/* It seems like maybe a good idea to establish string as a global variable so it can be used for all functions without having to re-write it for each function*/ +let word = String -function pigLatin(word) { - - // Your code here - +function letters(word) { + return word.split('') } +function pigLatin(word) { + const vowelArray = ["a", "e", "i", "o", "u"] + if (vowelArray.includes(word[0])) { + console.log("firstIsVowel") + return word=word+"way"; + }else if (chars = letters(word)){ + console.log("firstNotVowel") + return chars.slice(1).join('') + chars[0] + 'ay'; +} +} function getPrompt() { rl.question('word ', (answer) => { From 934b5f48fc06fd7f4759a36d8f5529f9f3f8f1bf Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Sun, 4 Feb 2018 13:28:03 -0600 Subject: [PATCH 2/2] Pig Latin progress --- 02week/pigLatin.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 0b736fe79..811edc017 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -12,9 +12,7 @@ const rl = readline.createInterface({ /* The first function below splits the word or string into an array of substrings, which allows the following functions to move letters (which now make up the new array) around. */ /* It seems like maybe a good idea to establish string as a global variable so it can be used for all functions without having to re-write it for each function*/ -let word = String - -function letters(word) { +function splitWordIntoArray(word) { return word.split('') } @@ -22,11 +20,12 @@ function pigLatin(word) { const vowelArray = ["a", "e", "i", "o", "u"] if (vowelArray.includes(word[0])) { console.log("firstIsVowel") - return word=word+"way"; - }else if (chars = letters(word)){ + return word+"way"; + }else { console.log("firstNotVowel") + const chars = splitWordIntoArray(word) return chars.slice(1).join('') + chars[0] + 'ay'; -} + } } function getPrompt() {