-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathwarmup5.js
More file actions
54 lines (51 loc) · 1.78 KB
/
Copy pathwarmup5.js
File metadata and controls
54 lines (51 loc) · 1.78 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
// 1-create a data model to represent your classmates
// -think of different attributes of your classmates? what do all of them have ? (DONE)
// -create a factory function. (DONE)
// -create an array to hold the classmates that you created and what you created to it . (DONE)
// -write a function called displayFriend that takes a mate as an argument and returns the important information in a readable way. ( DONE)
// -write a function called addFriend that takes a mate as an argument and add it to you classMates arraya done
// -calculate the number of male friends that your class have by writing a function called nbOfMale. (DONE)
// -Write a function searchMates that, given a query and an array of Mates,
// searches the array of mates for "matching" mate. You will decide what way you want to write your search algorithm.
var arrOfClassMates = [];
function classMates(name, age, gender, major) {
return arrOfClassMates =
[ {
['age']: age,
['gender']: gender,
['major']: major
}
]
}
////
function displayFriend(mate) {
for (var i = 0; i < mate.length; i++) {
return arrOfClassMates[i][mate]['age'] + ' ' + arrOfClassMates[i][mate]['major'] ;
}
}
////
function addFriend() {
arrOfObj.push({});
}
function nbOfMale(arrOfObj) {
let maleCounter = 0
for (var i = 0; i < arrOfObj.length; i++) {
if(arrOfObj[i]["gender"] === 'male') {
return maleCounter++;
}
}
}
function searchMates(arrayofObj, query) {
var queryArr=[];
for (var i = 0; i < query.length; i++) {
for( var key in arrayofObj ) {
if (key === query[i] ) {
console.log('Its Entering')
queryArr.push(arrayofObj[i][key]);
}
}
}
return queryArr;
}
arr = [{Name: 'adam', age: '18', gender: 'male'},{Name: 'ALi', age: '21', gender: 'male'}];
////