loading...

Discussion on: Daily Challenge #22 - Simple Pig Latin

Collapse
ynndvn profile image
La blatte

Here goes a JavaScript oneliner

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

pigIt('Hello world !');
"elloHay orldway !"

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(' ')

unPigIt('igPay atinLay siay oolcay');
"Pig Latin is cool"

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

Nailed it 👌🔥🔥