All academies
All challenges

Swap a Generic Pair

mediumgenerics100 XP

Problem

Write swap<A, B>(pair: [A, B]): [B, A] that returns a new tuple with the two elements in reverse order. The types must swap too: passing [number, string] must produce a value typed [string, number].

Expected output

["one",1]
[42,true]

Hints

Stuck? Reveal hints one at a time.

Solution

Try solving it yourself first — revealing is always available.

Press Run in the editor — your console output is checked automatically.
No errors
Loading...

Console output appears here. Press Run or just type — the code compiles automatically.