AniUI Academy
easy+150 XPPractice

Peek at a value mid-pipeline

Halfway through a map/filter/reduce chain something is wrong and you want to see the value. Pulling the chain apart into temporary variables to add a console.log is a hassle, so you slip in a function that runs a side effect and hands the value straight back.

Implement tap(value, fn). Call fn with value, then return value itself — the exact same reference, not a copy, and whatever fn returned is discarded. Because the value is passed by reference, fn is free to mutate an object it receives and those mutations are visible on the returned value.

What it has to do

  • Return the original value, ignoring whatever fn returns.
  • Call fn exactly once with the value as its only argument.
  • Return the identical reference, not a copy.
  • Let fn mutate an object value in place.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.