-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a1953f
commit 7e331c0
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(' '); | ||
} |