Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Max of Arguments

A Closer Look at Functionseasy

Course · Section 10: A Closer Look at Functions · Lecture 135: Default Parameters

Implement `maxOf(...nums)` returning the largest argument, or `null` when called with no arguments.

Sample tests

Input: maxOf(3, 1, 2)
Output: 3
Input: maxOf()
Output: null

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Math.max() of no arguments returns -Infinity, so return null for the empty call.

Learning resources

  • MDN: Functions
Visualize this concept: The this Keyword →
Approach & explanation (try first)

Collect arguments with rest, return null when none, otherwise spread into Math.max.

Loading...
⌘/Ctrl + Enter

Run your code to see results.