-
Notifications
You must be signed in to change notification settings - Fork 1
/
1023.js
40 lines (33 loc) · 1.19 KB
/
1023.js
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
function camelMatch(queries, pattern) {
let result = [];
for (let query of queries) {
result.push(judgeCanMatch(query, pattern))
}
return result;
function judgeCanMatch(item, pattern) {
let patternUpcase = {};
let itemUpcase = {}
for (let char of item) {
if (char >= 'A' && char <= 'Z') {
itemUpcase[char] = itemUpcase[char] ? itemUpcase[char] + 1 : 1;
}
}
for (let char of pattern) {
if (char >= 'A' && char <= 'Z') {
patternUpcase[char] = patternUpcase[char] ? patternUpcase[char] + 1 : 1;
}
}
// console.log('patternUpcase is', patternUpcase);
// console.log('itemUpcase is', itemUpcase);
if (Object.keys(itemUpcase).length !== Object.keys(itemUpcase).length || !Object.keys(itemUpcase).every(key => patternUpcase[key] === itemUpcase[key])) {
return false;
}
for (let char of pattern) {
if (item.indexOf(char) < 0) {
return false;
}
}
return true;
}
}
console.log(camelMatch(["CompetitiveProgramming","CounterPick","ControlPanel"], 'CooP'))