function len(list, count){
count = count || 0;
return list.next ? len(list.next, count + 1) : list.value !== undefined ? count + 1 : count
}
var list = {
value: 1,
next: {
value: 2,
next: {
value: 3,
next: {
value: 4,
next: null
}
}
}
};
print(len(list))
print(len({}))
print(len({value:0, next:null}))
ZnVuY3Rpb24gbGVuKGxpc3QsIGNvdW50KXsKICAgIGNvdW50ID0gY291bnQgfHwgMDsKICAgIHJldHVybiBsaXN0Lm5leHQgPyBsZW4obGlzdC5uZXh0LCBjb3VudCArIDEpIDogbGlzdC52YWx1ZSAhPT0gdW5kZWZpbmVkID8gY291bnQgKyAxIDogY291bnQKfQoKdmFyIGxpc3QgPSB7Cgl2YWx1ZTogMSwKCW5leHQ6IHsKCQl2YWx1ZTogMiwKCQluZXh0OiB7CgkJCXZhbHVlOiAzLAoJCQluZXh0OiB7CgkJCQl2YWx1ZTogNCwKCQkJCW5leHQ6IG51bGwKCQkJfQoJCX0KCX0KfTsKCnByaW50KGxlbihsaXN0KSkKCnByaW50KGxlbih7fSkpCgpwcmludChsZW4oe3ZhbHVlOjAsIG5leHQ6bnVsbH0pKQ==