- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patharrayToList.js
More file actions
Latest commit
37 lines (32 loc) · 509 Bytes
/
Copy patharrayToList.js
File metadata and controls
37 lines (32 loc) · 509 Bytes
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
functionarrayToList(array){
varlist={};
list.value=array[array.length-1];
list.rest=null;
for(leti=array.length-2;i>=0;i--){
vartemp={};
temp.value=array[i];
temp.rest=list;
list=temp;
}
returnlist;
}
vararray=[1,2,3,4,5,6];
varlist=arrayToList(array);
//test
functionprintList(list){
if(list){
console.log(list.value);
printList(list.rest);
}else{
console.log('null');
}
}
printList(list);
// result:
// 1
// 2
// 3
// 4
// 5
// 6
// null