-
Notifications
You must be signed in to change notification settings - Fork 0
/
Higherorderfunction.js
56 lines (51 loc) · 1.45 KB
/
Higherorderfunction.js
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
// ========================================================================
// problem 1 , method 1
function outerFun(array) {
function innerFunc(innerElem) {
return innerElem + 1;
}
const innerArray = array.map(innerFunc);
return innerArray;
}
const result = arr.map(outerFun);
// problem 1 , method 2
const incrementedArray = practiceData.map((outerArray) =>
outerArray.map(innerElement => innerElement + 1)
);
console.log(incrementedArray);
// problem 2
const evenArray = practiceData.map((outerArray) =>
outerArray.filter(innerElement => innerElement % 2 === 0)
);
console.log(evenArray);
//
//========================================================================
//
const answer = array.map((element, index) => index % 2 === 0 ? element * 10 : element * 2);
//
//========================================================================
//
const carObject = {};
carBrands.forEach((brand, index) => {
carObject[brand] = carModel[index];
});
console.log(carObject);
//
//========================================================================
//
arr.reduce((acc, curr) => {
acc = [...acc, ...curr]
return acc
}, [])
//
//========================================================================
//
const capitals = countries.map(item => item.toUpperCase())
console.log(capitals);
// ========================================================================
{const arr = [1,2,3,4,5,6]
function myfun(){
const mynum = arr.filter(x=>x*)
return mynum
}
console.log(myfun()) }