Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

apply with an Arguments Array

A Closer Look at Functionsmedium

Course · Section 10: A Closer Look at Functions · Lecture 140: The call and apply Methods

Given a `sumAll` function that sums its arguments, implement `sumApply(nums)` that calls it via `apply`, passing `nums` as the argument list.

Sample tests

Input: sumApply([1,2,3])
Output: 6
Input: sumApply([])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • call would pass the array as a single argument, not spread it.
Approach & explanation (try first)

apply spreads the array as individual arguments to the function.

Loading...
⌘/Ctrl + Enter

Run your code to see results.