-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodewarsChallenge70.js
More file actions
29 lines (25 loc) · 1.42 KB
/
codewarsChallenge70.js
File metadata and controls
29 lines (25 loc) · 1.42 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
let student1 = { name: 'James', age: 26, gender: 'male' };
let student2 = { name: 'Julia', age: 27, gender: 'female' };
let student3 = { name: 'Richard', age: 31, gender: 'male' };
/* const roster = [student1, student2, student3]; // Create an array of student objects
const getStudentNames = (roster) => {
return roster.map(student => student.name); // Extract the 'name' property from each student object
};
const getStudentAges = (roster) => {
return roster.map(student => student.age); // Extract the 'age' property from each student object
};
console.log(getStudentNames(roster)); // Log an array of student names: ['James', 'Julia', 'Richard']
console.log(getStudentAges(roster)); // Log an array of student ages: [26, 27, 31]
console.log(roster); // Log the original roster array of student objects
*/
const roster = new WeakSet([student1, student2, student3]);
const getStudentNames = (roster) => {
return Array.from(roster).map(student => student.name); // Convert WeakSet to array and extract names
};
const getStudentAges = (roster) => {
return Array.from(roster).map(student => student.age); // Convert WeakSet to array and extract ages
};
console.log(roster.has(student1)); // Check if student1 is in the WeakSet: true
console.log(getStudentNames(roster)); // Log an array of student names: ['James', 'Julia', 'Richard']
console.log(getStudentAges(roster)); // Log an array of student ages: [26, 27, 31]
console.log(roster);