Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if you could handle words that do not have vowels.

if(firstPosition > 0){
return word.slice(firstPosition) + word.slice(0, firstPosition) + 'ay';
}
return word + 'yay';

}

function firstVowel(word){
for (let i=0; i<word.length; i++){
if('aeiou'.indexOf(word[i]) !== -1){
return i;
}
}
}

}

// the first function called in the program to get an input from the user
// to run the function use the command: node main.js
Expand Down
21 changes: 21 additions & 0 deletions myPractice/practice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@



function translatePigLatin(str){
let firstPosition = firstVowelPosition(str);
if(firstPosition > 0){
return str.slice(firstPosition) + str.slice(0, firstPosition) + 'ay';
}
return str + 'yay';

}

function firstVowelPosition(str){
for (i=0; i<str.length; i++){
if('aeiou'.indexOf(str[i]) !== -1){
return i;
}
}
}

console.log(translatePigLatin('consonants'));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"eslint": "^3.19.0",
"functional-javascript-workshop": "^1.0.6",
"htmllint-cli": "github:kevincolten/htmllint-cli",
"http-server": "^0.11.1",
"http-server": "^0.12.3",
"javascripting": "^2.6.1",
"jsdom": "^11.6.2",
"mocha": "^5.0.0",
Expand Down