Guest User

Untitled

a guest
Jan 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. const vowelRegex = new RegExp('^[aeiou]', 'g');
  2. function pigLatin(str){
  3. if (vowelRegex.test(str)) {
  4. return `${str}way`;
  5. } else {
  6. const first = str.slice(0, 1);
  7. const rem = str.slice(1, str.length);
  8. return `${rem}${first}ay`;
  9. }
  10. }
  11. const testInputs = ['paragraphs', 'california', 'algorithm'];
  12. testInputs.forEach(function (ip) {
  13. console.log(pigLatin(ip));
  14. });
  15.  
  16. // output
  17. // aragraphspay
  18. // aliforniacay
  19. // algorithmway
Add Comment
Please, Sign In to add comment