-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.js
More file actions
23 lines (23 loc) · 730 Bytes
/
solution.js
File metadata and controls
23 lines (23 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* @param {string[]} words
* @return {string[]}
*/
var findWords = function(words) {
// js didn't support Long Integer, So we use another way to solve problem
let firstLine = 'qwertyuiop',
secondLine = 'asdfghjkl',
lastLine = 'zxcvbnm'
let array = []
words.forEach(word => {
let first = second = last = 0
Array.from(new Set(word.toLowerCase().split(''))).forEach(char => {
if (firstLine.indexOf(char) !== -1) first = 1
else if (secondLine.indexOf(char) !== -1) second = 1
else if (lastLine.indexOf(char) !== -1) last = 1
})
if (first + second + last === 1) {
array.push(word)
}
})
return array
};