A reading repo, not an algorithms package
trekhleb/javascript-algorithms is one of the default GitHub stops for people searching “JavaScript algorithms” or “JavaScript data structures.” It contains implementations of common data structures and algorithms, with a README for each topic and links to further reading. The project is useful because it keeps the code close to the explanation. You can open linked list, heap, graph search, Dijkstra, dynamic programming examples, Big O notes, and tests without jumping between a textbook and a random gist.
The main mistake is treating it like a production dependency. This repo is an educational source tree. It is not an npm package you install into an app to get a supported algorithm API. If you need a battle-tested data structure for production, use the platform, a focused package, or write the small piece you need with tests. If you need to study how the piece works in JavaScript, this repo is a better fit.
That distinction also helps with interview prep. The repo can refresh an idea and give you runnable code. It cannot replace solving problems under time pressure, explaining tradeoffs out loud, or learning when an algorithm is the wrong tool.
What is inside
The repository is split under src into data-structures, algorithms, playground, and utils. The README tags entries with B for beginner and A for advanced. Data structures include linked lists, queue, stack, hash table, heap, priority queue, trie, trees, graph, disjoint set, bloom filter, and LRU cache.
The algorithms side is broad. It covers math, sets, strings, searches, sorting, linked-list traversal, tree traversal, graph algorithms, cryptography examples, machine learning sketches, image processing, statistics, evolutionary algorithms, and uncategorized classics such as Tower of Hanoi, N Queens, Knight’s Tour, rain water, stock buy-sell, and valid parentheses.
The repo also organizes algorithms by paradigm: brute force, greedy, divide and conquer, dynamic programming, backtracking, and branch and bound. That makes it more useful than a flat snippet list. A learner can compare how a problem changes when solved through recursion, DP, or greedy choice.
The README is translated into many languages, including simplified Chinese. The contribution guide also allows folder-level README translations, so the translation story is larger than one top-level file. In practice, translation coverage varies by topic and issue threads show unfinished translation work. Use translations as help, not as a guarantee that every subfolder has complete local-language material.
How to run it locally
This is a repo to clone and inspect. The README gives the basic workflow:
npm install
npm run lint
npm test
For experiments, the README points to src/playground/playground.js and src/playground/__test__/playground.test.js. The idea is simple: write a small experiment in the playground file, add a test around it, and run the test suite.
There is one version detail worth checking before you lose time on setup. The README troubleshooting section mentions Node >=16, but package.json currently asks for Node >=22.0.0 and npm >=10.0.0 as of 2026-06. If your local install or tests fail, trust the current package.json first. This is exactly the kind of small drift that happens in popular educational repos: the top-level instructions are helpful, but the package metadata may be stricter.
Contributions are expected to be narrow. The contribution guide asks for focused pull requests, algorithm-specific README files with explanations and links, comments in code, linting, tests, and full coverage for new code. That bar is useful for readers too: each folder is meant to teach, not just pass a hidden benchmark.
Where it helps
The strongest use case is source reading with immediate tests. If you are reviewing binary search, a heap, DFS, KMP, Dijkstra, or a dynamic programming pattern, this repo gives you a JavaScript implementation and local tests in one place. It is also handy for people teaching algorithms in JavaScript, because the folder structure lets students move from a concept page to code to test.
It also helps JavaScript developers who learned the language through web work and later need CS vocabulary. Seeing an AVL tree or union find in JavaScript removes the small translation tax of reading every example in Java, C++, or Python. That does not make JavaScript the best language for every algorithm, but it lowers the barrier for web developers.
The repo is less useful when you need a complete course. It does not give a semester plan, graded exercises, or a progression from prerequisites to final project. For that, ossu/computer-science is closer to a curriculum. It is also less useful when you need an interview system with problem lists, spaced review, and behavioral prep. For that, jwasham/coding-interview-university has a more explicit study-plan angle.
Where it can mislead
Educational algorithm repositories attract drive-by contributions. Recent pull requests as of 2026-06 include small fixes, new algorithm proposals, translation fixes, a security policy proposal, and input-validation patches. Some are useful. Some look like low-context attempts to add material because the repo is famous.
The issue tracker shows the same pattern. There are real correctness concerns, such as cycle path construction and Dijkstra priority updates. There are translation gaps. There are feature requests that do not fit the repo well, such as TypeScript type definitions for code that is not meant to be consumed as a library. There are also comments calling out AI-generated issue text and posts. For a learner, the signal is this: read merged code and tests first, not every open proposal.
Another limitation is algorithm pedagogy. A clean implementation can still hide why a choice is correct, why a proof works, or what input shape breaks a naive version. The per-topic README files help, but they are not a substitute for a real algorithms text. Use the repo to see code, then use books, lectures, and problem practice to build judgment.
Comparison with similar algorithm repos
| Repository | Stars | Language | License | Best use |
|---|---|---|---|---|
| trekhleb/javascript-algorithms | 196,072 | JavaScript | MIT | Readable JS examples with explanations, tests, and playground use |
| TheAlgorithms/Python | 221,848 | Python | MIT | Broad multi-contributor algorithm collection in Python |
| TheAlgorithms/JavaScript | 34,183 | JavaScript | GPL-3.0 | Community algorithms collection tied to TheAlgorithms site |
| TheAlgorithms/Java | 65,819 | Java | MIT | Java implementations with active updates and a large contributor base |
As of 2026-06, the local snapshot shows trekhleb/javascript-algorithms above 196,000 stars. TheAlgorithms/Python is larger by stars and is better if Python is your study language. TheAlgorithms/JavaScript is closer by language, but its GPL-3.0 license and community-collection style make it a different choice. The trekhleb repo feels more like a curated study book with code next to notes.
Reading the star curve
The sampled star history shows a sharp 2018 breakout, then long accumulation. That shape matches what this repo became: not a new framework wave, but a durable search result for “algorithms in JavaScript.” The recent push date and merged pull requests show that it is not abandoned, but the large backlog of open issues and pull requests means you should treat it as a popular educational repo with selective maintenance.
Popularity is still useful here. It means examples have been read by many learners and obvious mistakes are more likely to surface. It does not mean every implementation is the best current teaching example or every open issue has been triaged.
Related repos
- TheAlgorithms/Python for a much larger Python algorithm collection.
- ossu/computer-science for a full CS self-study curriculum.
- jwasham/coding-interview-university for interview-oriented planning.
- practical-tutorials/project-based-learning for project-based practice.
- freeCodeCamp/freeCodeCamp for guided exercises and curriculum infrastructure.
FAQ
Is trekhleb/javascript-algorithms an npm library?
No. It is best treated as an educational source repository. Clone it, read it, run tests, and experiment in the playground. Do not assume it is a supported runtime dependency for production apps.
What Node version should I use?
As of 2026-06, package.json asks for Node >=22.0.0 and npm >=10.0.0. The README troubleshooting text still mentions Node >=16, so use the package metadata if the two disagree.
Is it good for interview prep?
It is useful for reviewing concepts and JavaScript implementations. It is not a complete interview plan. Pair it with timed problem practice, explanation practice, and a broader roadmap if interviews are the goal.
How do I run examples?
Install dependencies, run the test suite, and use the playground files under src/playground. The repo is organized around tests and readable implementations rather than a public CLI.
How does it compare with TheAlgorithms/JavaScript?
Both cover algorithms in JavaScript. trekhleb/javascript-algorithms has a curated study-repo feel and MIT license. TheAlgorithms/JavaScript is a community collection tied to TheAlgorithms and uses GPL-3.0. Pick based on license needs, contribution style, and which explanations you prefer.