leetcode Keyboard Row

来源:互联网 发布:宁波淘宝托管公司排名 编辑:程序博客网 时间:2024/06/06 19:07

Keyboard Row

Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]
正则结合数组过滤
var findWords = function(words) {    return words.filter((w) => {       if(          // *代表0或多次 即任意次数          !/^[qwertyuiop]*$/i.test(w) &&           !/^[asdfghjkl]*$/i.test(w) &&          !/^[zxcvbnm]*$/i.test(w)       ){          return false;       } else{          return true;       }    });}
0 0
原创粉丝点击