Add Two Numbers
1 var addTwoNumbers = function(l1, l2) {
2 var sum = l1.val + l2.val,
3 l3 = new ListNode(sum % 10),
4 node = l3;
5
6 l1 = l1.next;
7 l2 = l2.next;
8 sum = Math.floor(sum / 10);
9
10 while (l1 || l2 || sum != 0) {
11 sum += (l1 ? l1.val : 0) + (l2 ? l2.val : 0);
12 node.next = new ListNode(sum % 10);
13 node = node.next;
14 l1 = l1 ? l1.next : null;
15 l2 = l2 ? l2.next : null;
16 sum = Math.floor(sum / 10);
17 }
18
19 return l3;
20 };