A simple test-driven structure for practicing JavaScript interview questions.
Each question has its own directory with a descriptive name:
questions/question1-promise-all/- Promise.all() polyfillquestions/question2-map/- Array.map() polyfillquestions/question3-{name}/- (Future questions)
Each question directory contains:
index.js- Contains the problem, solution, and tests (all in one runnable file)README.md- Problem description and instructions
Navigate to the question directory and run:
cd questions/question1-promise-all
node index.jsOr from the root directory:
node questions/question1-promise-all/index.jsThis will:
- Execute the solution code
- Run all test cases
- Show ✓ (green) for passing tests
- Show ✗ (red) for failing tests
- Display a summary at the end
🧪 Running tests for: Question 1: Promise.all() polyfill
──────────────────────────────────────────────────
✓ All promises resolve successfully
✗ One promise rejects
Error: ...
──────────────────────────────────────────────────
📊 Results: 1 passed, 1 failed
❌ Some tests failed
- Create a new directory:
questions/questionN-{problem-name}/ - Create
index.jsin that directory - Import the TestRunner:
const TestRunner = require('../../test-runner'); - Create a runner instance:
const runner = new TestRunner('Question N: Description'); - Add tests using
runner.test('description', async () => { ... }) - Run tests with
runner.run(); - Optionally add a
README.mdwith problem description
- Question 1: Promise.all() polyfill implementation (
questions/question1-promise-all/) - Question 2: Array.map() polyfill implementation (
questions/question2-map/)
For YouTube tutorial series - feel free to fork and practice!