Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const vowelRegex = new RegExp('^[aeiou]', 'g');
- function pigLatin(str){
- if (vowelRegex.test(str)) {
- return `${str}way`;
- } else {
- const first = str.slice(0, 1);
- const rem = str.slice(1, str.length);
- return `${rem}${first}ay`;
- }
- }
- const testInputs = ['paragraphs', 'california', 'algorithm'];
- testInputs.forEach(function (ip) {
- console.log(pigLatin(ip));
- });
- // output
- // aragraphspay
- // aliforniacay
- // algorithmway
Add Comment
Please, Sign In to add comment