Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 1011 Bytes

824.山羊拉丁文.md

File metadata and controls

42 lines (36 loc) · 1011 Bytes

824.山羊拉丁文

/*
 * @lc app=leetcode.cn id=824 lang=typescript
 *
 * [824] 山羊拉丁文
 */

// @lc code=start
function toGoatLatin(sentence: string): string {}
// @lc code=end

解法 1: 模拟

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

Case

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)
}