Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Fix an Argument with bind

A Closer Look at Functionsmedium

Course · Section 10: A Closer Look at Functions · Lecture 141: The bind Method

Using `bind` to pre-set the first argument of an `add(a, b)` function to `5`, implement `addFiveToAll(nums)` that maps the bound adder over `nums`.

Sample tests

Input: addFiveToAll([1,2,3])
Output: [6,7,8]
Input: addFiveToAll([0])
Output: [5]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • bind returns a new function; it does not call the original immediately.
Approach & explanation (try first)

bind creates a partially applied adder with the first argument fixed at 5.

Loading...
⌘/Ctrl + Enter

Run your code to see results.