-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathcategorize-new-member.js
More file actions
39 lines (33 loc) · 913 Bytes
/
categorize-new-member.js
File metadata and controls
39 lines (33 loc) · 913 Bytes
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
// [[18, 20],[45, 2],[61, 12],[37, 6],[21, 21],[78, 9]]
// senior >= 55
// -2 to +26;
function openOrSenior(data) {
// an array to store the categories
const categories = [];
// iterate over the data
for (let i = 0; i < data.length; i++) {
const member = data[i];
const age = member[0];
const handicap = member[1];
// check if the current item index 0 is greater than or equal to 55
if (age >= 55 && handicap > 7) {
categories.push('Senior');
} else {
categories.push('Open');
}
}
return categories;
}
// ["Open", "Open", "Senior", "Open", "Open", "Senior"]
function openOrSenior(data) {
return data.map(([age, handicap]) => {
if (age >= 55 && handicap > 7) {
return 'Senior';
} else {
return 'Open';
}
});
}
function openOrSenior(data) {
return data.map(([age, handicap]) => age >= 55 && handicap > 7 ? 'Senior' : 'Open');
}