From 09d84546e2bac8f9433517afc5ed24394ffff095 Mon Sep 17 00:00:00 2001 From: Dillon7Peterson Date: Tue, 9 Jun 2020 13:16:44 -0500 Subject: [PATCH] pig latin project working --- main.js | 24 +++++++++++++++++++++--- myPractice/practice.js | 21 +++++++++++++++++++++ package.json | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 myPractice/practice.js diff --git a/main.js b/main.js index 1c92f304..6d7c700d 100644 --- a/main.js +++ b/main.js @@ -10,12 +10,30 @@ const rl = readline.createInterface({ output: process.stdout }); - +//pigLatin('car') //=> 'arcay' +//pigLatin('create') //=> 'eatecray' +//pigLatin('pony') //=> 'onypay' +//pigLatin('egg') //=> 'eggyay' +//let word = 'car'; const pigLatin = (word) => { - // Your code here + // Your code here + let firstPosition = firstVowel(word); + if(firstPosition > 0){ + return word.slice(firstPosition) + word.slice(0, firstPosition) + 'ay'; + } + return word + 'yay'; + + } + +function firstVowel(word){ + for (let i=0; i 0){ + return str.slice(firstPosition) + str.slice(0, firstPosition) + 'ay'; + } + return str + 'yay'; + +} + +function firstVowelPosition(str){ + for (i=0; i