DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Keyboard Row -

var findWords = function (words) {
    let firstRowSet = new Set("qwertyuiop".split(''));
    let secondRowSet = new Set("asdfghjkl".split(''));
    let thirdRowSet = new Set("zxcvbnm".split(''))
    let result = [];

    for (let word of words) {
        let charSplit = word.toLowerCase().split('')
        if (charSplit.every(char => firstRowSet.has(char))) {
            result.push(word)
        } else if (charSplit.every(char => secondRowSet.has(char))) {
            result.push(word)
        } else if (charSplit.every(char => thirdRowSet.has(char))) {
            result.push(word)
        }
    }

    return result
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)