DEV Community

Discussion on: Daily Challenge #22 - Simple Pig Latin

Collapse
 
ynndvn profile image
La blatte • Edited

Here goes a JavaScript oneliner

const pigIt = (s) => s.split(' ').map(e=>e.match(/\w/)?`${e.slice(1)}${e[0]}ay`:e).join(' ')
Enter fullscreen mode Exit fullscreen mode
pigIt('Pig Latin is cool');
"igPay atinLay siay oolcay"

pigIt('Hello world !');
"elloHay orldway !"
Enter fullscreen mode Exit fullscreen mode

And just for fun, an unPigIt oneliner too!

const unPigIt = (s) => s.split(' ').map(e=>e.match(/\w/)?e[e.length-3]+e.slice(0,-3):e).join(' ')

Enter fullscreen mode Exit fullscreen mode
unPigIt('igPay atinLay siay oolcay');
"Pig Latin is cool"

unPigIt('elloHay orldway !');
"Hello world !"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
petecapecod profile image
Peter Cruckshank

Nailed it 👌🔥🔥