-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathNextValue_M2.js
60 lines (56 loc) · 1.42 KB
/
NextValue_M2.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
55
56
57
58
59
60
<<<<<<< HEAD
const array=[
{id:'one',next:"two", value:null},
{id:'two',next:"three", value:null},
{id:'three',next: null, value:null}
];
var result=[]
function updatevalue(array){
if(result.length==0){
for(var i in array){
if(array[i].next==null){
result.unshift(array[i])
array.splice(array[i],1)
}
}
}
for(var j in array){
if(result[0].id==array[j].next){
array[j].value=result[0]
result.unshift(array[j])
array.splice(array[j],1)
updatevalue(array)
break
}
}
}
updatevalue(array.reverse())
=======
const array=[
{id:'one',next:"two", value:null},
{id:'two',next:"three", value:null},
{id:'three',next: null, value:null}
];
var result=[]
function updatevalue(array){
if(result.length==0){
for(var i in array){
if(array[i].next==null){
result.unshift(array[i])
array.splice(array[i],1)
}
}
}
for(var j in array){
if(result[0].id==array[j].next){
array[j].value=result[0]
result.unshift(array[j])
array.splice(array[j],1)
updatevalue(array)
break
}
}
}
updatevalue(array.reverse())
>>>>>>> 218d06a5590b574fc3a6c257200b997baa9ad88e
console.log(result)