-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay22Reacursion.html
46 lines (42 loc) · 1.24 KB
/
Day22Reacursion.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>day 22</title>
</head>
<body>
<script>
//recursion concept in javascript
function add(x){
if(x==1){// base value
return 1
}
return x+add(x-1);
}
console.log(add(3));//6
let startup={
developement:{
software:[{person1:"someone",salary:3000},{person2:"karthi",salary:2000}]
},
testing:{
manual:[{emp1:"madhavan",salary:3000},{emp2:"yathavan",salary:2000}],
automation:[{emp3:"krishna",salary:3000},{emp2:"partha",salary:2000}]
}
}
function salaryemp(start){
if(Array.isArray(start)){
return start.reduce((prev,current)=>prev+current.salary,0)
}
else{
let sum=0;
for(let sal of Object.values(start)){
sum+=salaryemp(sal);//recursion happens
}
return sum;
}
}
console.log(salaryemp(startup));//15000
</script>
</body>
</html>