-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathNextvalue_Recursive.js
50 lines (48 loc) · 1.17 KB
/
Nextvalue_Recursive.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
<<<<<<< HEAD
const array=[
{id:'one',next:"two", value:null},
{id:'two',next:"three", value:null},
{id:'three',next: "four", value:null},
{id:'four',next: null, value:null}
];
var nextindex=0
function updatearray(array){
updatevalue(array,0)
function updatevalue(array,index){
if(array[index].next==null){
return array[index]
}
else{
array[index].value=updatevalue(array,index+1)
return array[index]
}
}
}
updatearray(array)
var arr=array
arr=JSON.stringify(array)
=======
const array=[
{id:'one',next:"two", value:null},
{id:'two',next:"three", value:null},
{id:'three',next: "four", value:null},
{id:'four',next: null, value:null}
];
var nextindex=0
function updatearray(array){
updatevalue(array,0)
function updatevalue(array,index){
if(array[index].next==null){
return array[index]
}
else{
array[index].value=updatevalue(array,index+1)
return array[index]
}
}
}
updatearray(array)
var arr=array
arr=JSON.stringify(array)
>>>>>>> 218d06a5590b574fc3a6c257200b997baa9ad88e
console.log(arr)