Skip to content

Commit

Permalink
Simple Pig Latin
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltomasik committed Jan 26, 2019
1 parent 4a1953f commit 7e331c0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions SimplePigLatin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://www.codewars.com/kata/simple-pig-latin

// Description:
// Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.

// Examples
// pigIt('Pig latin is cool'); // igPay atinlay siay oolcay
// pigIt('Hello world !'); // elloHay orldway !

function pigIt(str){
const words = str.split(' ');

const convertedWords = words.map(word => {
var letters = /^[A-Za-z]+$/;
return word.match(letters) ?
word.substring(1) + word[0] + 'ay' : word;
});

return convertedWords.join(' ');
}

0 comments on commit 7e331c0

Please sign in to comment.