1function merge (L1, L2) {
2 let L3 = { data: null, next: null };
3 let prev = L3;
4
5 while (L1 != null || L2 != null) {
6 if (L1 === null) {
7 prev.next = L2;
8 L2 = L2.next;
9 continue;
10 }
11
12 if (L2 === null) {
13 prev.next = L1;
14 L1 = L1.next;
15 continue;
16 }
17
18 if (L1.data <= L2.data) {
19 prev.next = L1;
20 L1 = L1.next;
21 } else {
22 prev.next = L2;
23 L2 = L2.next;
24 }
25
26 prev = prev.next;
27 }
28
29 return L3.next;
30};
31