Skip to content

Commit b76e000

Browse files
committed
hk
1 parent 13cf905 commit b76e000

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const redius =[3,1,2,4];
2+
/*this is the code for the calculating the area
3+
of the circle now logic is */
4+
const calculateArea= function(redius){
5+
const output=[];
6+
for(let i=0;i<redius.length;i++){
7+
output.push(Math.PI*redius[i]*redius[i]);
8+
}
9+
return output;
10+
};
11+
console.log(calculateArea(redius));
12+
/* now if we want to calculate the perimeter
13+
of the circle then we will have to do another
14+
same kind of the logic */
15+
const calculateperimeter=function(redius){
16+
const output=[];
17+
for(let i=0;i<redius.length;i++){
18+
output.push(Math.PI*2*redius[i]);
19+
}
20+
return output;
21+
}
22+
console.log(calculateperimeter(redius));
23+
// /* there is one thing that we might have
24+
// noticed and that is that we are repeating
25+
// the code again and again due to that this is
26+
// not an efficient way of running the code
27+
// and wiht the help of the higher order function
28+
// we can basically reduce the code lenght drastically
29+
// by passing the logic and the fucntion
30+
// in the code*/
31+
32+
// // repeating code now
33+
const repeat=function(redius,logic){
34+
const output=[];
35+
for(let i=0;i<redius.length;i++){
36+
output.push(logic(redius[i]));
37+
} return output;
38+
}
39+
//logic for the area
40+
const area=function(red){
41+
return Math.PI*red*red;
42+
43+
};
44+
console.log(repeat(redius,area));
45+
/* now this is the way to do the higher
46+
order function and by doing that we are able to
47+
minimize the code that is written and
48+
we are making a fucntion get accept a funciton
49+
and we are able to pass a funcion in a funciotn
50+
this is what a higher order fucniton is like*/

0 commit comments

Comments
 (0)