All challenges

TypeScript · easy

List bleed

#21

Situation

Warehouse API promised a snapshot, but callers can push into the returned array and add "leak" to production stock. getStock is exposing the live shelf instead of a copy.

Objective

Return an independent list for each shelf. After a caller pushes "leak", a fresh getStock("desk") must still be ["pen","ink"] (length 2).

The repo at start

workspace/
└── src/
    └── inventory.ts   (returns the live stock array)

Checks you will turn green

  • exports getStock
  • the desk shelf returns pen and ink
  • another shelf returns its own items
  • stock length stays 2 after push

Concepts

arraysmutation

Play it in your terminal

With sharpen installed, this command opens exactly this challenge in your local arena:

sharpen 21

First time? The full install is right below.

How to play

  1. 1 Install Claude Code if you do not have it yet: claude.com/claude-code
  2. 2 Install sharpen from npm:
    npm install -g @juanwmedia/sharpen
  3. 3 Then launch it; the arena opens in your browser:
    sharpen 21
  4. or Or try it without installing anything:
    npx @juanwmedia/sharpen 21
  5. 4 And to update when a new version ships:
    sharpen update