All files / leetCode 0500.ts

100% Statements 18/18
100% Branches 6/6
100% Functions 1/1
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  4x 4x   4x 9x 9x 9x   9x 16x 9x 7x     9x 21x 4x 4x       9x 5x     4x    
export default function findWords(words: string[]): string[] {
  const rows = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
  const result: string[] = []
 
  for (const word of words) {
    const normalizedWord = word.toLowerCase()
    let flag = true
    let row = 0
 
    while (row < rows.length) {
      if (rows[row].includes(normalizedWord[0]))
        break
      row++
    }
 
    for (let i = 1; i < normalizedWord.length; i++) {
      if (rows[row].includes(normalizedWord[i]) === false) {
        flag = false
        break
      }
    }
 
    if (flag)
      result.push(word)
  }
 
  return result
}