-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey-points.js
More file actions
95 lines (82 loc) · 2.33 KB
/
key-points.js
File metadata and controls
95 lines (82 loc) · 2.33 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const data = {
"users": [
{
"id": 1,
"name": "John",
"age": 25,
"hobbies": ["reading", "gaming"],
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
},
{
"id": 2,
"name": "Jane",
"age": 30,
"hobbies": ["hiking", "photography"],
"address": {
"street": "456 Oak St",
"city": "Someville",
"state": "NY",
"zip": "54321"
}
},
{
"id": 3,
"name": "Bob",
"age": 35,
"hobbies": ["cooking"],
"address": {
"street": "789 Elm St",
"city": "Othercity",
"state": "FL",
"zip": "67890"
}
}
]
};
// Filter users over age 30 and return their names and hobbies
const filteredUsers = data.users.filter(user => user.age > 30)
.map(user => ({name: user.name, hobbies: user.hobbies}));
console.log(filteredUsers);
In this example, we have a JSON object with an array of users. We use the filter() method to filter the users over the age of 30, and then the map() method to return an array of objects containing only the user's name and hobbies. The resulting filteredUsers array will contain two objects representing users Jane and Bob:
[ { "name": "Jane", "hobbies": ["hiking", "photography"]
},
{
"name": "Bob",
"hobbies": ["cooking"]
}
]
data.users.filter(user => user.hobbies.includes("gaming")); //user whose hobbies include gaming
let productId = this.route.snapshot.paramMap.get('id');
const data = [
{
"StoryPoints": -1,
"TaskEstimate": -100
},
{
"StoryPoints": 41,
"TaskEstimate": -100
},
{
"StoryPoints": 71,
"TaskEstimate": -100
}
];
data.sort((a, b) => a.StoryPoints - b.StoryPoints);
console.log(data);
async fetchUsers() {
try {
const response = await fetch('https://randomuser.me/api/?results=5');
const data = await response.json();
console.log(data.results);
} catch (error) {
console.error(error);
}
}
A function along with reference to its outer environment together forms a closure. Or in other words, A Closure is a combination of a function and its lexical scope bundled together. eg:
result.erase(std::unique(result.begin(), result.end()), result.end());
filters duplicate vectors in 2D vector