Seen this whiteboard challenge online and can't seem to figure it out. HELP!
Create a function that accepts an array of words as it's input.
Your function should return an array of all words that can be typed using letters of the alphabet that are only accessible on a single row of the standard American QWERTY keyboard.
For example:
// given
let words = [ 'sup', 'dad', 'tree', 'snake', 'pet'];
keyboardWords(words);
// return
['dad', 'tree', 'pet'];
And this is how far I've gotten.
const topKeys = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'];
const middleKeys = ['a', 's', 'd','f', 'g', 'h', 'j', 'k', 'l'];
const buttomKeys = ['z', 'x', 'c', 'v', 'b', 'n', 'm'];
let result = [];
let words = ['sup', 'dad', 'tree', 'snake', 'pet'];
for(let i in words) {
let eachWord = words[i];
eachWord.split('').forEach(function(c) {
console.log(c);
});
}
I've got to the point where I'm printing each word in the array but dont completly know what method to use to see if each letter in the words in a single array thats topKeys, middle Keys etc...
const buttomKeys = ['z', 'x', 'c', 'v', 'b', 'n', 'm'];
? There's no vowels. – Misology