-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.js
48 lines (40 loc) · 807 Bytes
/
style.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
41
42
43
44
45
46
47
48
let usersData
function studentsByGroup(students) {
fetch("https://mocki.io/v1/fcf2152e-707f-43c4-bb50-43c2ff29e697")
.then((response) => response.json())
.then((data) => (usersData = data));
}
studentsByGroup();
setTimeout(() => {
console.log(usersData)
const over18Users = usersData.filter(user => user?.age >= 18)
const result = over18Users.reduce((userData, currentUser) => (
{ ...userData, [currentUser.group]: [currentUser] }), {}
)
console.log(result)
}, "2000");
/* expected output: arrToObj(payload) ->
{
"1a": [
{
"group": "1a",
"age": 22,
"name": "John"
}
],
"2b": [
{
"group": "2b",
"age": 18,
"name": "Alise"
}
],
"2c": [
{
"group": "2c",
"age": 19,
"name": "Alex"
}
]
}
*/