I am trying to return the length of a linked object(list). However, the function I wrote doesn't return anything.
let linkedObject = { value: 1, rest: { value: 2, rest: { value: 3, rest: null } } }
function countDepth(liste, count = 0){
if (liste == null) return count
else {
count ++
liste = liste.rest
countDepth(liste, count)
}
}
console.log(countDepth(linkedObject))```
expected output:
'3'
actual output:
'undefined'