Estoy tratando de construir una lista vinculada usando una Class con JS. Dentro de mi Class , tengo una función llamada checkForEmptyNext() que recorre la lista y busca el nodo con next: property of null La función debe llamarse recursivamente a sí misma hasta que encuentre el node correcto
Lista enlazada
// 10 --> 15 --> 16 class LinkedList { constructor(value){ this.head = { value: value, next: null } this.tail = this.head; this.length = 1; } append(value){ if(this.head.next === null){ this.head.next = { value, next: null } this.tail = this.head.next; this.length++ }else{ this.checkForEmptyNext(value, this.head.next) } } checkForEmptyNext(value, node){ if(node.next === null){ node.next = { value, next: null } this.tail = node.next; this.length++ }else{ this.checkForEmptyNext(value, node.next) } } } const linked = new LinkedList(10); linked.append(5) linked.append(16) console.log(linked)El console.log está mostrando:
LinkedList { head: { value: 10, next: { value: 5, next: [Object] } }, tail: { value: 16, next: null }, length: 3 } ¿Por qué veo [Object] en lugar del valor serializado real?