{"record":{"id":"d8949c0aa281bc45","repo":"trekhleb/javascript-algorithms","slug":"can-t-remove-value-remove-method-is-not-implem","errorCode":null,"errorMessage":"Can't remove ${value}. Remove method is not implemented yet","messagePattern":"Can't remove (.+?)\\. Remove method is not implemented yet","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/data-structures/tree/red-black-tree/RedBlackTree.js","lineNumber":40,"sourceCode":"      // Make root to always be black.\n      this.makeNodeBlack(insertedNode);\n    } else {\n      // Make all newly inserted nodes to be red.\n      this.makeNodeRed(insertedNode);\n    }\n\n    // Check all conditions and balance the node.\n    this.balance(insertedNode);\n\n    return insertedNode;\n  }\n\n  /**\n   * @param {*} value\n   * @return {boolean}\n   */\n  remove(value) {\n    throw new Error(`Can't remove ${value}. Remove method is not implemented yet`);\n  }\n\n  /**\n   * @param {BinarySearchTreeNode} node\n   */\n  balance(node) {\n    // If it is a root node then nothing to balance here.\n    if (this.nodeComparator.equal(node, this.root)) {\n      return;\n    }\n\n    // If the parent is black then done. Nothing to balance here.\n    if (this.isNodeBlack(node.parent)) {\n      return;\n    }\n\n    const grandParent = node.parent.parent;\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/tree/red-black-tree/RedBlackTree.js#L22-L58","documentation":"RedBlackTree in this repository implements insertion and rebalancing but deliberately leaves deletion unimplemented: remove(value) unconditionally throws for every value. It is a documented-in-code limitation of an educational codebase, not a runtime condition you can influence — no argument, state, or configuration makes this method succeed. Any code path that deletes from a RedBlackTree will hit it.","triggerScenarios":"Calling tree.remove(value) on any RedBlackTree instance with any value; generic algorithms written against BinarySearchTree being handed a RedBlackTree, since remove() exists on the inherited interface and only fails at call time; tests copied from BinarySearchTree/AvlTree suites being run against RedBlackTree.","commonSituations":"Choosing RedBlackTree for its O(log n) guarantees and assuming the full CRUD surface exists; swapping an AvlTree import for RedBlackTree during a refactor; integrating this educational library into production code without auditing which methods are stubs.","solutions":["Switch to AvlTree (also self-balancing, same insert/find surface) or plain BinarySearchTree — both implement remove().","If you must keep a RedBlackTree, rebuild without the element: traverse values, filter out the target, and re-insert into a fresh tree.","Implement red-black deletion yourself in a subclass and override remove(), or fork the file — upstream ships no version where this method works.","Audit other methods you depend on before adopting a structure from this repo; stubs are marked by throw statements like this one."],"exampleFix":"// before\nimport RedBlackTree from './data-structures/tree/red-black-tree/RedBlackTree';\nconst tree = new RedBlackTree();\ntree.insert(1);\ntree.remove(1); // throws: Remove method is not implemented yet\n\n// after\nimport AvlTree from './data-structures/tree/avl-tree/AvlTree';\nconst tree = new AvlTree();\ntree.insert(1);\ntree.remove(1); // works, tree stays balanced","handlingStrategy":"fallback","validationCode":"import RedBlackTree from './data-structures/tree/red-black-tree/RedBlackTree';\n\nconst treeSupportsRemove = (tree) => !(tree instanceof RedBlackTree);\n\nfunction deleteFrom(tree, value) {\n  if (!treeSupportsRemove(tree)) {\n    // fallback: collect values, filter out the target, re-insert into an AvlTree\n    return null; // replace with the rebuild appropriate for your data\n  }\n  return tree.remove(value);\n}","typeGuard":"const treeSupportsRemove = (tree) => !(tree instanceof RedBlackTree);","tryCatchPattern":"try {\n  tree.remove(value);\n} catch (e) {\n  if (e.message.includes('Remove method is not implemented yet')) {\n    // fallback path: switch to AvlTree, or filter-and-reinsert into a fresh tree\n  } else {\n    throw e;\n  }\n}","preventionTips":["Before adopting a structure from this repo, scan its methods for throw-on-call stubs; RedBlackTree.remove is one.","If deletions are required, pick AvlTree or BinarySearchTree from the start.","Isolate tree selection behind your own interface so swapping implementations is a one-line change.","Cover every CRUD operation in integration tests against the concrete class you ship, not just the interface."],"tags":["red-black-tree","not-implemented","remove","data-structures","balanced-tree"],"backgroundTag":"not-implemented-yet","analyzedSha":"85293e3e2b88f4d2ce330d956b139cf628aa1e82","analyzedAt":"2026-08-24T05:59:10.417Z","schemaVersion":2},"datasetVersion":"2026-08-24T07:17:09.176Z"}