Thanks for taking the time to contribute! 🎉 This repo is meant to be a clean, approachable reference, so the bar is simple: readable code + a test.
- ➕ Add a new algorithm or data structure
- 📝 Improve an explanation, comment, or the README
- 🧪 Add edge-case tests to an existing module
- 🐛 Fix a bug (please include a test that reproduces it)
git clone https://github.com/rope-50/javascript-algorithms.git
cd javascript-algorithms
npm install
npm testRequires Node.js 20+. If you use a version manager (nvm, fnm, …), there's an
.nvmrc you can nvm use / fnm use.
- Create
src/<name>.jsexporting your function or class (ES module syntax). - Start the file with a docstring that explains the idea and states the time/space complexity.
- Re-export it from
src/index.js. - Add
tests/<name>.test.jswith a few meaningful cases (happy path + edge cases). Tests double as usage examples, so keep them readable. - Add a row to the relevant table in the README.
- Modern JavaScript:
const/let, arrow functions,Map/Setwhere they fit. - Prefer clarity over cleverness - this is a learning resource.
- Pure functions when possible: don't mutate the caller's input.
- Comments explain the why, not the obvious what.
npm testMake sure the whole suite is green. Then open a pull request with a short description of what you added or changed. That's it - thank you! 🙌