Skip to content

Commit 94a31a3

Browse files
authored
Create 824-goat-latin.js
1 parent b57dda7 commit 94a31a3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

824-goat-latin.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {string} sentence
3+
* @return {string}
4+
*/
5+
const toGoatLatin = function(sentence) {
6+
const arr = sentence.split(' ')
7+
const vowel = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])
8+
for(let i = 0, n = arr.length; i < n; i++) {
9+
const first = arr[i][0]
10+
const ma = vowel.has(first) ? 'ma' : ''
11+
const tmp = !vowel.has(first) ? `${arr[i].slice(1)}${first}ma` : arr[i]
12+
const suffix = 'a'.repeat(i + 1)
13+
arr[i] = `${tmp}${ma}${suffix}`
14+
}
15+
return arr.join(' ')
16+
};

0 commit comments

Comments
 (0)