给定一个单词列表,返回可以在美国键盘的一行上使用字母表键入的单词,如下图所示。
您可以多次使用键盘中的一个字符。 您可以假设输入字符串仅包含字母表的字母。
刚开始理解错了,一位只有asd这一行呢,结果是三行
findWords = function (words) { let one = ['q','w','e','r','t','y','u','i','o','p']; let two = ['a','s','d','f','g','h','j','k','l']; let three = ['z','x','c','v','b','n','m']; for(let i = words.length-1;i>=0;i--){ switch (true) { case ('-1' != one.indexOf(words[i].toLowerCase()[0])): for(let j = 1;j<words[i].length;j++){ if(one.indexOf(words[i][j]) == '-1'){ words.splice(i, 1); break; } } break; case ('-1' != two.indexOf(words[i].toLowerCase()[0])): for(let j = 1;j<words[i].length;j++){ if(two.indexOf(words[i][j]) == '-1'){ words.splice(i, 1); break; } } break; case ('-1' != three.indexOf(words[i].toLowerCase()[0])): for(let j = 1;j<words[i].length;j++){ if(three.indexOf(words[i][j]) == '-1'){ words.splice(i, 1); break; } } break; default: } } return words; }