/*
* @lc app=leetcode.cn id=824 lang=typescript
*
* [824] 山羊拉丁文
*/
// @lc code=start
function toGoatLatin(sentence: string): string {}
// @lc code=end
function toGoatLatin(sentence: string): string {
const words = sentence.split(' '),
chars = new Set('aeiouAEIOU')
for (let i = 0; i < words.length; i++) {
if (!chars.has(words[i][0])) words[i] = words[i].slice(1) + words[i][0]
words[i] += 'ma' + 'a'.repeat(i + 1)
}
return words.join(' ')
}
test.each([
{ input: { sentence: 'I speak Goat Latin' }, output: 'Imaa peaksmaaa oatGmaaaa atinLmaaaaa' },
{
input: { sentence: 'The quick brown fox jumped over the lazy dog' },
output:
'heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa',
},
])('input: sentence = $input.sentence', ({ input: { sentence }, output }) => {
expect(toGoatLatin(sentence)).toEqual(output)
}