Created
May 5, 2020 01:30
-
-
Save QaisPalekar/c590644cfd449547bfd58746221981ae to your computer and use it in GitHub Desktop.
Given an array of words, return the words that can be typed using letters of only one row on a keyboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getOneKeyRowWords(listOfWords) { | |
const row1 = ['q','w','e','r','t','y','u','i','o','p'], | |
row2 = ['a','s','d','f','g','h','j','k','l'], | |
row3 = ['z','x','c','v','b','n','m']; | |
return listOfWords.filter((word) => { | |
const uniquesChars = new Set(word.toLowerCase()); | |
return ( | |
row1.length === [...new Set([...row1, ...uniquesChars])].length || | |
row2.length === [...new Set([...row2, ...uniquesChars])].length || | |
row3.length === [...new Set([...row3, ...uniquesChars])].length | |
) ? true : false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment