Simple Pig Latin
Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.
Examples :
pigIt('Pig latin is cool'); // igPay atinlay siay oolcay pigIt('Hello world !'); // elloHay orldway !
π Needs ) λ¨μ΄μ 첫λ²μ§Έ κΈμλ₯Ό 맨 λμΌλ‘ κ°κ² νκ³ λ¨μ΄ λμ "ay"λ₯Ό μΆκ°νλΌ.
π Sol ) split μ¬μ©ν΄ λ¨μ΄ μͺΌκ°κ³ μλ‘μ΄ λ°°μ΄μ λ§λ€μ΄ join ν return
function pigIt(str) {
let result = [];
let arr = str.split(' ');
for ( let i = 0; i < arr.length; i++ ) {
result.push(arr[i].slice(1, arr[i].length) + arr[i][0] + 'ay')
}
return result.join(' ');
}
π‘ Other ways to solve ) map νμ©νμ¬ λμ± κ°λ¨νκ² μ½λ μ§€ μ μμ.
function pigIt(str) {
return str.split(' ').map(function(el) {
return el.slice(1) + el.slice(0,1) + 'ay';
}).join(' ');
}