-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrop-double-set.js
More file actions
43 lines (33 loc) · 979 Bytes
/
drop-double-set.js
File metadata and controls
43 lines (33 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function numKeypadSolutions(wordlist, keypads) {
let result = [];
let count = 0;
let keyPadSet = {}
for(let j = 0; j < keypads.length; j++){
keypadSet = new Set(keypads[j])
for(let i = 0; i < wordlist.length; i++){
let wordSet = new Set(wordlist[i])
let keyHasChar = false;
for(const wordChar of wordSet){
let lastChar = Array.from(wordSet).pop()
if(keypadSet.has(wordChar)){
keyHasChar = true;
} else {
keyHasChar = false;
break;
}
if( lastChar === wordChar && keyHasChar && wordlist[i].includes(keypads[j][0]) ){
count += 1
}
}
}//end of wordlist
result.push(count)
count = 0
}
return result
}
numKeypadSolutions(['APPLE', 'PLEAS', 'PLEASE'],
['AELWXYZ', 'AELPXYZ', 'AELPSXY', 'SAELPRT', 'XAEBKSY'] )
// numKeypadSolutions(['APPLE', 'PLEAS', 'PLEASE'],
// ['AELWXYZ'] )
//'AELWXYZ',
// Expected output: [0, 1, 3, 2, 0]