DEV Community

Discussion on: JavaScript Challenge 1: Simple Pig Latin

Collapse
 
pentacular profile image
pentacular

You might find it's simpler if you rearrange it slightly. :)

const latinifyWord = (word) =>
  word.match(/[A-z]/i)
    ? `${word.substr(1)}${word.substr(0,1)}ay`
    : word;

const pigIt = (str) =>
  str.split(' ').map(latinifyWord).join(' ');
Collapse
 
albertomontalesi profile image
AlbertoM

Yep, that also works :)