-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.js
More file actions
58 lines (53 loc) · 1.41 KB
/
report.js
File metadata and controls
58 lines (53 loc) · 1.41 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function solution(id_list, report, k) {
var answer = [];
const reportIdList = [];
for (var i = 0; i < id_list.length; i++) {
reportIdList.push([]);
answer[i] = 0;
}
report.forEach(element => {
const [user, ID] = element.split(" ");
const reportedID = id_list.findIndex(id => id === ID);
if (!reportIdList[reportedID].find(id => id === user)) {
reportIdList[reportedID].push(user);
}
});
reportIdList.forEach(item => {
if (item.length >= k) {
item.forEach(user => {
const userID = id_list.findIndex(id => id === user);
answer[userID] += 1;
});
}
});
return answer;
}
console.log(
solution(
["muzi", "frodo", "apeach", "neo"],
["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"],
2
)
);
// function solution(id_list, report, k) {
// report = [...new Set(report)];
// const reported = report.map(el => el.split(' ')[1]);
// const reported_final = [];
// const count = new Array(id_list.length).fill(0);
// reported.forEach(el => {
// count[id_list.indexOf(el)]++;
// });
// count.forEach((el, i) => {
// if(el >= k) {
// reported_final.push(id_list[i])
// }
// });
// count.fill(0);
// report.forEach((el) => {
// el = el.split(' ');
// if(reported_final.includes(el[1])) {
// count[id_list.indexOf(el[0])]++;
// }
// })
// return count;
// }