Practice
Coding Challenges
Solve OOP and NestJS-style problems in the browser. The judge compiles your TypeScript and runs assertions — earn XP for each solve.
Design a Counter class
Implement a `Counter` class with `inc()`, `dec()`, and `value()` methods. Start at 0. `dec()` must not go below 0.
Fix encapsulation on BankAccount
Make `balance` private. Expose `deposit(amount)`, `withdraw(amount)`, and `getBalance()`. Reject non-positive deposits and overdrafts by throwing Error.
Implement Animal → Dog inheritance
Create `Animal` with `name` and `speak()` returning `'...'`. `Dog` extends Animal and overrides `speak()` to return `name + ' woofs'`.
Composition: Car has-a Engine
Implement `Engine.start(): string` returning `'vroom'` and `Car` that takes Engine in the constructor and delegates `start()`.
Polymorphic Notifier
Define `interface Notifier { notify(msg: string): string }`. Implement `EmailNotifier` and `SmsNotifier`. Export function `alertAll(notifiers: Notifier[], msg: string): string[]`.
Apply constructor Dependency Injection
Create `interface Mailer { send(to: string): string }`, `ConsoleMailer`, and `AuthService` that receives Mailer via constructor and `register(email)` calls mailer.send.
Refactor tight coupling
Refactor so `ReportService` depends on `interface Database { query(sql: string): string[] }` injected in the constructor. Provide `MemoryDatabase` returning `['ok']` for any query. `run()` returns db.query('select 1').
Implement a Repository
Implement `UserRepo` with `save(id, name)` and `find(id)`. Then `UserService` with constructor(repo) and `register(id, name)` / `get(id)`.
Apply SRP — split the god class
Replace GodService with UserService.create(name), Mailer.send(to), and Audit.log(event). `pipeline(name, email)` should create user, send mail, log 'created:'+name, and return the user object.
Factory-style provider
Write `createGreeter(prefix: string)` returning `{ greet(name: string): string }` that returns prefix + name. `appGreet` should use createGreeter('Hi ').
10 challenges available — more coming in the 250+ set.