CodeVetter · Repo Unpack · Contributor handoff
trekhleb/javascript-algorithms
Safe mental model: this is an educational algorithm catalog, not an app — optimize for clarity and pedagogy over cleverness or performance. Before editing, read CONTRIBUTING.md, .eslintrc, jest.config.js and the target module's README. Conventions: one default export per file, file name matches export (camelCase for functions, PascalCase for classes), heavy JSDoc typedefs and explanatory comments, co-located __test__ dirs, toString()-based assertions. Verify with npm test and npm run lint; keep 100% coverage or CI fails.
- Read first: CONTRIBUTING.md (PR rules: focused one-algorithm PRs, README required, 100% coverage), jest.config.js (testRegex + thresholds), .eslintrc (airbnb + relaxed rules), and the module's own README.md for the math/intent.
- House style: every module default-exports one function or class, annotates params/returns with JSDoc (including @typedef blocks for callback shapes), and explains non-obvious steps with inline comments — match this rather than introducing terse idioms.
- Tests belong in a sibling `__test__` dir named <Module>.test.js; for shared algorithm families reuse the harness (SortTester statics) instead of duplicating fixtures.
- Run `npm test -- <pattern>` for a single module (e.g. 'playground'), `npm test` for the full suite, `npm run lint` before committing (husky does this anyway), and `npm run coverage` to check the CI gate locally.
- Node >=22 and npm >=10 are required; dependencies are dev-only — do not add runtime dependencies, and prefer plain JS over new libraries since pedagogy is the product. (inferred)
- Do not create index.js or try to 'package' the repo — the missing main entry is the status quo; consumers deep-import files like src/data-structures/linked-list/LinkedList.js. (inferred)
- Mutating methods on data structures conventionally return `this` for chaining (append/prepend/insert/reverse); preserve that contract when editing or tests asserting chains will break.
- When touching Comparator behavior, remember Comparator.reverse() mutates the compare function in place — several tests rely on reversing sort order via this mechanism.
- The seam-carving test resolves PNG fixtures relative to process CWD (./src/...), so always run jest from the repo root; new file-IO tests should follow the `__tests__` plural dir convention so testRegex matches.
- Known traps: Graph throws on duplicate addVertex/addEdge (pre-check or expect the throw), HashTable keys must be strings (hash() iterates chars), and delete() on LinkedList removes ALL matching nodes, not just the first.