CodeVetter
← All unpacks
CodeVetter · Repo Unpack evidence

trekhleb/javascript-algorithms

Scanned commit 85293e3e2b dated 2026-07-25 — last upstream commit. Generated by codevetter 1.12.0 on 2026-09-22.

github.com/trekhleb/javascript-algorithms ↗ · 630 files · 1.8 MB

JavaScript Algorithms and Data Structures 🇺🇦 UKRAINE IS BEING ATTACKED BY RUSSIAN ARMY.

Deep analysis by swe-2 via the devin CLI on 2026-09-22 (runtime not recorded) — every claim below links to its cited source files.

Overview

trekhleb/javascript-algorithms is a curated, test-driven educational collection of classic computer-science data structures and algorithms implemented in plain ES-module JavaScript, organized as ~150 self-contained topic folders under src/data-structures and src/algorithms, each paired with a README (often translated into ~20 locales) and a Jest test suite. It is not an application or published library — there is no runtime entrypoint, no index.js despite the package.json "main" field, and the only 'product' surface is the code itself plus the npm test/lint/coverage scripts. Distinctive traits: a shared Comparator/abstract-Sort callback design lets learners inject custom comparison and visiting hooks, and Jest coverage thresholds of 100% statements/functions/lines are enforced via npm run coverage in CI.

System map

The repo is a flat monorepo of independent algorithm/data-structure modules — there is no app server, CLI, or build artifact; the runtime boundary is simply Node.js >=22 running Jest 30 over ES-module sources transpiled by @babel/preset-env. Code lives in three subtrees: src/data-structures (14 categories), src/algorithms (14 topic dirs), plus src/utils and a src/playground scratch area. Cross-cutting wiring is minimal: a single shared Comparator utility and a small inheritance graph (Sort -> QuickSort et al.; Heap -> MinHeap/MaxHeap -> PriorityQueue). Quality gates are npm run lint (eslint airbnb config) on pre-commit via husky, and npm run coverage in GitHub Actions CI on Node 22.x with Codecov upload.

Feature catalog

Features here are the algorithm/data-structure modules themselves — each is a self-contained folder with one default-exported function or class, a README.md (frequently translated), and a co-located test directory. The catalog spans ~30 data-structure implementations across 14 categories and ~100 algorithm implementations across 14 topics, ranging from beginner (factorial, bubble sort) to advanced (red-black tree, seam carving, k-means). There are no routes, screens, or CLI subcommands; the 'user-facing' surface is the module APIs plus the playground scratch file.

Data flow

Data flow is simple and uniform: callers (tests or the playground) invoke a module's default export with plain JS values; the module mutates or returns in-memory structures; results are compared with Jest matchers. There is no persistence, network, or external state — the only file IO is the seam-carving test streaming PNG fixtures through pngjs. The Comparator-injection pattern and traversal callbacks are the two mechanisms that let callers steer internal behavior without subclassing.

Behavior traces

Three flows were traced end-to-end. (1) Test execution: npm test -> jest -> testRegex match -> test file imports module under test -> assertions on return values/toString. (2) Sorting: QuickSort construction -> Sort.initSortingCallbacks -> sort() recursion driven by Comparator and visitingCallback. (3) BFS over a graph: callback init with seen-set -> Queue enqueue/dequeue -> getNeighbors -> allowTraversal gating. A fourth flow (seam carving) shows the only IO path: PNG load -> energy map -> DP seam -> in-place pixel shift.

Testing signals

Testing is the project's backbone: Jest 30 with ~112 __test__/__tests__ directories and ~178 spec files co-located beside implementations. Coverage thresholds are aspirational-strict (100% statements/functions/lines, 95% branches) but only enforced when the `coverage` script runs — plain `npm test` collects no coverage. Shared tester harnesses (SortTester, FourierTester) standardize whole algorithm families, and CI runs lint + coverage with Codecov upload on Node 22.

Risk map

Security exposure is minimal — no network, auth, secrets, or shell-out; the only file IO is the seam-carving test reading local PNG fixtures. The real risks are correctness and maintainability quirks: deliberately simplified primitives (char-sum hash, first-element pivot), mutating APIs, a missing package entrypoint, mixed test-dir naming, and a coverage gate that only runs in CI. Educational intent means several implementations trade robustness for clarity.

Extension points

The whole repo is designed as an additive catalog: a new algorithm or data structure is a new folder that plugs in via file convention, not registration. Two deliberate seams exist inside the code — constructor-injected Comparator functions and the Sort/Heap/MinHeap inheritance chain plus traversal callbacks — and CONTRIBUTING.md spells out the social conventions (one algorithm per PR, README required, 100% coverage).

Contributor handoff

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.

Languages

LanguageFilesShare of source
JavaScript361100%
Markdown259docs/config
JSON1docs/config
YAML1docs/config

Start reading here

Probable source entrypoint: src/ — inferred from the directory tree and manifest, not the upstream docs.

Source roots

src/ (597 files)

Source layout — src/

PathFiles
src/algorithms/100
src/data-structures/161
src/playground/3

Repository structure

Top-level pathFiles
src/597
.husky/1
.github/1

Docs found: CONTRIBUTING.mdREADME.md

Package

package.json — javascript-algorithms-and-data-structures v0.0.4, 11 declared dependencies.

@babel/cli@babel/preset-env@types/jesteslinteslint-config-airbnbeslint-plugin-importeslint-plugin-jesteslint-plugin-jsx-a11yhuskyjestpngjs

CI & config entrypoints

Structural health signals

Average score 8.2/10 across 96 analyzed source files; 0 hotspots surfaced.

These are deterministic review leads — size, churn, and structural signals — not proof of a bug in this project.

Recent history