FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Function Length

10mins

Implement a function functionLength(fn) that returns the number of parameters expected by a function.

The function should:

  • Accept a single argument:
    • fn: A function
  • Return the number of parameters the function expects (its length property)

Example

function sum(a, b, c) { return a + b + c; } functionLength(sum); // 3 function greet(name) { return "Hello " + name; } functionLength(greet); // 1 function noParams() { return 42; } functionLength(noParams); // 0

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests