-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathData_Modeling.js
More file actions
67 lines (61 loc) · 2.27 KB
/
Data_Modeling.js
File metadata and controls
67 lines (61 loc) · 2.27 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
// 1-create a data model to represent some of your classmates
// -think of different attributes of your classmates? what do all of them have ?
// -create a factory function.
// -create an array to hold the classmates that you have created.
// -write a function called displayFriend that takes a mate as an argument and returns the important information in a readable way.
// -write a function called addFriend that takes a mate as an argument and add it to you classMates array.
// -calculate the number of male friends that your class have by writing a function called nbOfMale.
// -Write a function searchMates that, given a query and an array of Mates,
// searche the array of mates for "matching" mate. You will decide what way you want to write in your search algorithm.
<<<<<<< HEAD
function makeClassmate(name, age, nationality,Gender){
return {name: name,
age: age,
nationality: nationality,
Gender: Gender
}
}
var classmate1 = makeClassmate("Nada Taha", 34 , "Yemenian", "Female");
var classmate2 = makeClassmate("Hanan Nouman", 24 , "Palestinian", "Female");
var classmate3 = makeClassmate("Raed bani Awwad", 22 , "Jordanian", "Male");
var classmate4 = makeClassmate("Ammar Halbouni", 23 , "Jordanian", "Male");
var classMates = [classmate1,classmate2,classmate3, classmate4];
function displayFriend(friend){
if (friend["Gender"]=== "Female"){
return friend.name + ", "+friend.age +" years old" + ", and she is "+friend.nationality;}
if (friend["Gender"]=== "Male"){
return friend.name + ", "+friend.age +" years old" + ", and he is "+friend.nationality;}
}
function addFriend (friend){
classMates.push(friend);
return classMates;
}
function nbOfMale(array){
var counter = 0;
for (var i=0; i<array.length; i++){
if (array[i]["Gender"] === "Male"){
counter++;
}
}
return "number of male classmates is: "+ counter;
}
function searchMates (array, query){
var result =[];
var c =0;
for (var i=0; i< array.length; i++){
for (var key in array[i]){
if (array[i][key]=== query){
result[c] = array[i];
c++;
}
else if (typeof (array[i][key]) == "string"){
if (array[i][key].indexOf(query)>=0){
result[c] = array[i];
c++;
}
}
}
} return result;
}
=======
>>>>>>> bc6e2edad1c6d0c213c8f26ffb373fe17961ef71