Please help! Why is my output still undefined?
var addTwoNumbers = function(l1, l2) {
function printListReverse(list){
let current = list;
let digits =[];
while (current){
digits.unshift(current.val);
current = current.next;
}
return(parseInt(digits.join("")));
}
let listReverse1 = printListReverse(l1);
let listReverse2 = printListReverse(l2);
let listSum = listReverse1+listReverse2;
class Node {
constructor(data, next = null){
this.data = data;
this.next = next;
}
}
class LinkedList{
constructor(){
this.head = null;
}
}
let list = new LinkedList();
LinkedList.prototype.insertAtBeg = function (data){
let newNode = new Node(data);
newNode.next = this.head;
this.head = newNode;
return this.head;
}
let listArr = String(listSum).split("")
for (digit of listArr){
list.insertAtBeg(parseInt(digit))
}
return(list);
}