forked from BushraAlabsi/Toy_Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHigherFunctionsEach2.js
More file actions
60 lines (55 loc) · 1.42 KB
/
Copy pathHigherFunctionsEach2.js
File metadata and controls
60 lines (55 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
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
/*
using improved each create function that returns an array with all the names in the array
if the index is even
var x = [{name : 'Jon',age : 45}, {name : 'Ali', age : 28},
{name :'Omar', age :17},{name :'Ola', age :37}, {name 'Salwa', age : 22}];
pName(x); = > ['Jon', 'Omar', 'salwa']
*/
function each(array, func) {
for (var i = 0; i < array.length; i++) {
func(array[i], i);
}
}
function pName(argument) {
<<<<<<< HEAD
each(argument, function(obj, i){
return argument.value[i]
})
=======
// your code is here
>>>>>>> cc67d8a9778e9402221541866539cacea4645ed9
}
/*
1) using improved each with objects, create function that print every element inside the object
var obj_2 = {name: 'Ibrahim', age : 67, phone : '078-0000000'}
printValue(obj_2); =>
Ibrahim
67
078-0000000
var obj_1 = {name: 'Salim', age : 15, phone : '079-0000000'}
printValue(obj_1); =>
Salim
15
079-0000000
*/
function each(coll, func) {
if (Array.isArray(coll)) {
for (var i = 0; i < coll.length; i++) {
func(coll[i], i);
}
}
else {
for (var key in coll) {
func(coll[key], key);
}
}
}
function printValue(obj) {
<<<<<<< HEAD
each(array,function(obj,valu){
return value
})
=======
// your code is here
>>>>>>> cc67d8a9778e9402221541866539cacea4645ed9
}