Skip to content
dreamcode
dreamcode
Map
Generic Sky Box
Section challenge · AdvancedTypeScript
Reward: +60 XP
PROBLEM

Generic Sky Box

Finish the generic class Box<T>:

  • getValue() returns the value the box was created with.
  • map(fn) takes a function from T to U and returns a new Box<U> holding fn(value). The original box must not change.

Then write boxPipeline(start): put start in a box, map it with "add 1", then map the result with "double it", and return the final value.

Examples
boxPipeline(3)
8
boxPipeline(0)
2
solution.ts
TYPESCRIPT
Saved as you type

Tests

0 of 4 passing
  • boxPipeline(3)
    boxPipeline(3)
    expected 8
  • boxPipeline(0)
    boxPipeline(0)
    expected 2
  • boxPipeline(-1)
    boxPipeline(-1)
    expected 0
  • boxPipeline(10)
    boxPipeline(10)
    expected 22
On the line
+60 XP
Pass all 4 tests to claim it.