-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
36 lines (33 loc) · 876 Bytes
/
kata.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
function findHack(arr) {
const scores = {
'A': 30,
'B': 20,
'C': 10,
'D': 5
}
let answ = [];
for (let i = 0; i < arr.length; i++) {
let count = 0;
if (arr[i][2].length >= 5 &&
arr[i][2].length === arr[i][2]
.filter((s) => s === 'A' | s === 'B').length) {
count += 20;
}
arr[i][2].map((i) => {
if (scores.hasOwnProperty(i)) {
count += scores[i]
}
})
if (count !== arr[i][1]) {
answ.push(arr[i][0])
}
}
return answ;
}
var array = [
["name1", 150, ["B", "A", "A", "C", "A", "A"]],
["name2", 120, ["B", "A", "A", "A"]],
["name3", 160, ["B", "A", "A", "A", "A"]],
["name4", 140, ["B", "A", "A", "C", "A"]]
];
console.log(findHack(array)) // ["name2","name4"]