Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Árbol de búsqueda binario y "No se pueden leer las propiedades de nulo"

Tengo un árbol de búsqueda binario genérico que usa una función de comparación para evaluar qué valor es mayor. Este es mi método de eliminación:

 remove(data) { const removeHelper = (node, data) => { if (!node) return null; if (this.#comparator(data, node.data) === 0) { if (!node.left && !node.right) return null; if (!node.left) return node.right; if (!node.right) return node.left; let tmp = node.right; while (!tmp.left) { tmp = tmp.left; } node.data = tmp.data; node.right = removeHelper(node.right, tmp.data); } else if (this.#comparator(data, node.data) === -1) { node.left = removeHelper(node.left, data); return node; } else { node.right = removeHelper(node.right, data); return node; } }; this.root = removeHelper(this.root, data); return data; }

Sigo recibiendo el error: TypeError: Cannot read properties of null (reading 'left') en referencia a esta línea: (while (! tmp.left))

¿Cómo se supone que mi método de eliminación no debe leer los tipos de propiedad de nulo si eso es de lo que funciona todo el método?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!