Skip to content

Commit 122e9c4

Browse files
committed
creating array and take array elements as radius and find area
1 parent 0ab3083 commit 122e9c4

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

higherorderfunc.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@
33
//or Return a function or Both
44
//for ex : ForEach Method alwaays takes another function inside it
55
//So forEach is a higher order function
6-
function f(val)
7-
{
8-
6+
function f(val) {
7+
val();
8+
return function g() { console.log("Ojha"); };
9+
910
}
10-
f( function fx(){
1111

12-
})
12+
var gres = f(function fx() {
13+
console.log("Kirtti");
14+
15+
});
16+
gres();
1317
//or ex:
14-
var arr = [1,2,3,4,5];
15-
arr.forEach(function(){})
18+
var arr = [1, 2, 3, 4, 5];
19+
arr.forEach(function () { })
20+
21+
22+
const radius = [3, 4, 5, 2];
23+
function findArea(radius) {
24+
const res =[];
25+
for(let i=0;i < radius.length; i++)
26+
{
27+
res.push(Math.PI*radius[i]*radius[i]);
28+
}
29+
return res;
30+
}
31+
32+
console.log(findArea(radius));
33+
//and similarly create for find diameter and circumference
34+
//That would be not a good programming skill to repeat the code
35+
//so the optimized and good programming skill would be

0 commit comments

Comments
 (0)