SOURCE

var ListTree = function(val){
    this.val = val
    this.next = null
}
function add(a,b){
    let result = new ListTree(0)
    let head = result
    let temp = 0
    //console.log(result)
    while(true){
        let v = result
        console.log(result)
        if(a&&b){
            let sum = a.val+b.val+temp
            v.val = sum%10
            temp = (sum-sum%10)/10
            a = a.next
            b = b.next
            console.log(v.val)
            console.log(temp)
            if(temp!=0){
                //console.log("ok")
                let addition = new ListTree(0)
                v.next = addition
                v = v.next
            }
            continue
        }else if(a&&!b){
            let sum = a.val+temp
            v.val = sum%10
            temp = (sum-sum%10)/10
            a = a.next
            //console.log(result.val)
            //console.log(temp)
            if(a||(temp!=0)){
                //console.log("ok")
                let addition = new ListTree(0)
                v.next = addition
                v = v.next
            }
            continue
        }else if(!a&&b){
            let sum = b.val+temp
            v.val = sum%10
            temp = (sum-sum%10)/10
            b = b.next
            //console.log(result.val)
            //console.log(temp)
            if(b||(temp!=0)){
                console.log("ok")
                let addition = new ListTree(0)
                v.next = addition
                v = v.next
            }
            continue
        }else if(!a&&!b){
            //console.log("jinwei")
            if(temp!=0){
                v.val = temp
            }
            break
        }
    }
    return head
}
var a = new ListTree(2)
a.next = new ListTree(4)
//a.next.next = new ListTree(3)
var b = new ListTree(5)
b.next = new ListTree(6)
b.next.next = new ListTree(4)
console.log(add(a,b))
console 命令行工具 X clear

                    
>
console