Skip to content

Instantly share code, notes, and snippets.

@QaisPalekar
Created May 5, 2020 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QaisPalekar/c590644cfd449547bfd58746221981ae to your computer and use it in GitHub Desktop.
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.
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