How sir-gon/algorithm-exercises-js works
1. This repository is a collection of algorithm solutions written in Node.js ES6, organized as two main problem domains: HackerRank and Project Euler. It is not an application with runtime services; the “architecture” is primarily a code-and-test system for solving exercises.
2. The core source tree lives under src/, and is split by problem source:
- src/hackerrank/... contains challenge solutions grouped by category such as warmup, implementation, interview preparation kit, and projecteuler.
- src/projecteuler/... contains numbered Project Euler solutions plus shared helpers and small library abstractions.
- src/problem0000.js and src/examples/ appear to be small standalone/example entry points.
3. Each exercise is typically implemented as a single solution module paired with a Jest test file in the same directory. The tests are the main execution path of the repository: they load the solution function, feed it fixtures or inline cases, and verify the result. This TDD-style pairing is the central structural pattern.
4. Many problems also include JSON fixture files beside the tests, such as *.testcases.json, *.small.testcases.json, or *.big.testcases.json. These files drive data-heavy or boundary-heavy test cases and are part of the test data layer, not application state.
5. Some problems include multiple implementations of the same algorithm, usually a brute-force version and an optimized version. This shows up in filenames like *_bruteforce.js, *_optimized.js, *-alt.js, and corresponding tests. In the architecture diagram, these are alternative solution branches under the same problem family, not separate subsystems.
6. Shared code is minimal but important:
- src/hackerrank/lib/ contains utility structures like BigIntMath.js and Node.js.
- src/projecteuler/helpers/ contains reusable math/string helpers such as prime generation, divisors, Collatz, palindromes, matrix utilities, and numeric conversions.
- src/projecteuler/lib/ contains tree/node builders used by some Euler problems.
These shared modules are the main internal dependencies across many solutions.
7. There is also a small cross-cutting support layer:
- src/constants/ holds shared constants, notably date/time-related values.
- src/logger.js suggests a lightweight logging abstraction used by tests and solution runs.
These are support utilities rather than core algorithm logic.
8. The documentation layer is substantial and mirrors the source taxonomy. docs/ contains markdown writeups for many HackerRank and Project Euler problems, including solution notes. These docs are not just user-facing; they likely capture reasoning and algorithm choices that correspond to the code variants.
9. The repository is heavily test-driven and quality-gated. Jest is the runtime test framework, while ESLint, Prettier, Markdown linting, YAML linting, and security scans are enforced through configuration files and GitHub Actions workflows. The CI boundary is therefore “source + docs must pass static checks and tests before merge.”
10. External dependencies are intentionally limited at runtime. The README emphasizes “vanilla code,” and the architecture reflects that: solutions are mostly self-contained pure functions with deterministic inputs/outputs, minimizing coupling to libraries or services.
11. Docker and Make are used as environment wrappers around the same codebase. compose.yaml, Dockerfile, and Makefile provide reproducible commands for linting, testing, and running a production-like container. This creates a platform boundary: local Node execution, containerized development/testing, and final image validation.
12. The GitHub Actions workflows form the automation layer. They cover unit tests, linting, code scanning, dependency/security checks, and image building. In an architecture diagram, this is the CI/CD lane that consumes the repo but does not affect runtime behavior.
13. A useful way to diagram the repository is as three layers:
- Problem inputs/fixtures and documentation,
- Algorithm implementations and reusable helpers,
- Jest/CI/Docker tooling that validates the implementations.
The main data flow is: fixtures and problem statements inform solution modules, which are exercised by tests, which are then validated by local tooling and CI.
14. There are no databases, message queues, web endpoints, or third-party service integrations in the application sense. The only “external systems” that materially affect architecture are the Node.js runtime, Jest test runner, Docker/Compose, and GitHub Actions.
Main entry points: jest.config.js Jest · projecteuler Euler Problems · interview_preparation_kit Interview Kit · implementation Implementation
Components 17
Source & Problems
Problem solutions, paired tests, and fixtures.
- Warmup · Small HackerRank exercises with one solution and one test per problem.
src/hackerrank/warmup - Implementation · HackerRank implementation challenges and their paired tests.
src/hackerrank/implementation - Interview Kit · Grouped HackerRank interview-preparation problems, sometimes with alternative algorithms.
src/hackerrank/interview_preparation_kit - Euler Problems · Project Euler solutions, variants, and problem-specific tests.
src/projecteuler - Problem 0000 · Standalone top-level exercise entry point.
src/problem0000.js - Examples · Small demonstration entry points and tests.
src/examples
Shared Code
Reusable helpers and support modules used across solutions.
- HR Lib · Hackerrank-specific helpers such as BigInt math and node structures.
src/hackerrank/lib - Euler Helpers · Reusable numeric, string, matrix, and combinatorics helpers.
src/projecteuler/helpers - Euler Lib · Binary-tree builders and node abstractions for Euler problems.
src/projecteuler/lib - Constants · Cross-cutting shared constants, mainly date/time values.
src/constants - Logger · Lightweight logging abstraction used by tests and runs.
src/logger.js
Docs
Problem writeups and solution notes mirrored from the source taxonomy.
- HackerRank Docs · Markdown problem notes for warmup, implementation, interview kit, and Euler-on-HackerRank.
docs/hackerrank - Euler Docs · Markdown writeups for Project Euler problems.
docs/projecteuler
Tooling
Local development, linting, and container wrappers.
- Jest · Primary execution and assertion framework for solution modules and fixtures.
jest.config.js - Lint & Format · ESLint, Prettier, Markdown lint, YAML lint, and related config.
eslint.config.js - Docker/Make · Container and command wrappers for reproducible local validation.
Dockerfile
Automation
GitHub Actions and quality gates.
- GitHub Actions · Automated test, lint, scan, and image-build workflows.
.github/workflows
Connections 24
- HackerRank Docs → Warmup: documents · Problem notes explain solution choices and variants.
- HackerRank Docs → Implementation: documents · Problem notes explain solution choices and variants.
- HackerRank Docs → Interview Kit: documents · Problem notes explain solution choices and variants.
- Euler Docs → Euler Problems: documents · Problem notes and writeups mirror solution taxonomy.
- Warmup → Jest: tested by · Each solution is exercised through a colocated test file.
- Implementation → Jest: tested by · Each solution is exercised through a colocated test file.
- Interview Kit → Jest: tested by · Paired tests drive the solution modules and fixtures.
- Euler Problems → Jest: tested by · Problem modules are validated by colocated tests.
- Examples → Jest: tested by · Example code has its own test companion.
- HR Lib → Implementation: supports · Shared Hackerrank utilities are imported by problem solutions.
- HR Lib → Interview Kit: supports · Shared Hackerrank utilities are imported by problem solutions.
- Euler Helpers → Euler Problems: supports · Common numeric and structural helpers are reused across Euler problems.
- Euler Lib → Euler Problems: supports · Tree/node abstractions back selected Euler solutions.
- Constants → Implementation: shared by · Cross-cutting values are consumed where needed.
- Constants → Euler Problems: shared by · Cross-cutting values are consumed where needed.
- Logger → Jest: supports · Logging is used during tests and local runs.
- Docker/Make → Jest: wraps · Containerized and make-based commands run the same tests and checks.
- Docker/Make → Lint & Format: wraps · Local wrappers provide reproducible linting and formatting commands.
- GitHub Actions → Jest: runs · CI executes the test suite.
- GitHub Actions → Lint & Format: runs · CI enforces static checks and formatting.
- GitHub Actions → Docker/Make: builds · CI validates container/image workflows.
- Euler Problems → Euler Helpers: uses · Euler solutions rely on shared helper modules.
- Euler Problems → Euler Lib: uses · Euler solutions rely on shared tree utilities.
- Interview Kit → HR Lib: uses · Selected challenge solutions depend on Hackerrank helpers.