CodeVetter · Repo Unpack · Feature catalog
trekhleb/javascript-algorithms
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.
- LinkedList provides a full fluent API — prepend, append, insert(value, rawIndex), delete(value), find({value, callback}), deleteTail, deleteHead, fromArray, toArray, toString(callback), reverse — with most mutating methods returning `this` for chaining.
- Graph supports directed and undirected modes via a constructor flag, auto-adds missing vertices on addEdge, throws on duplicate vertex/edge insertion, and offers getNeighbors, findEdge, getWeight, reverse (for directed graphs), getVerticesIndices and getAdjacencyMatrix.
- HashTable implements separate-chaining collision handling by filling each of its 32 default buckets with a LinkedList and tracking keys in a parallel `keys` object for O(1) has().
- LRUCache implements O(1) get/set using a nodesMap plus an internal doubly-linked list with sentinel head/tail nodes, promote() and evict() helpers, and a hard capacity eviction; an alternative LRUCacheOnMap implementation ships alongside it.
- BloomFilter exposes insert/mayContain backed by a closed-over boolean array (createStore) and three hand-rolled hash functions (hash1/hash2/hash3), demonstrating false-positive semantics.
- Eleven sorting algorithms live under src/algorithms/sorting (bubble, bucket, counting, heap, insertion, merge, quick, radix, selection, shell) all extending the abstract Sort class and honoring compareCallback/visitingCallback hooks.
- Graph algorithms cover traversals (breadthFirstSearch, depthFirstSearch) plus articulation-points, bellman-ford, bridges, detect-cycle, dijkstra, eulerian-path, floyd-warshall, hamiltonian-cycle, kruskal, prim, strongly-connected-components, topological-sorting and travelling-salesman.
- The image-processing topic implements content-aware seam carving: resizeImageWidth shrinks an ImageData-like object width via energy-map calculation, DP lowest-energy seam finding, and in-place seam deletion.
- Math topics include factorial (iterative and recursive variants), fibonacci, primality-test, sieve-of-eratosthenes, euclidean-algorithm, fourier-transform, matrix operations, complex-number, bits manipulation and liu-hui pi approximation.
- Cryptography offers caesar-cipher, hill-cipher, rail-fence-cipher and polynomial-hash (PolynomialHash plus a SimplePolynomialHash variant) — educational ciphers, not production crypto.
- src/playground/playground.js is an explicit sandbox: it imports an algorithm (factorial by default), exposes a playground() function, and is exercised by src/playground/__test__/playground.test.js via `npm test -- 'playground'`.
- Every topic folder ships a README.md with explanations and further-reading links, and most offer translations as README.xx-XX.md files (e.g., linked-list alone has 10 locale variants).