← Back to challenges

Return First and Last Parameter

JavaScriptHardlanguage_fundamentals

Instructions

Write two functions:

  1. firstArg() should return the first parameter passed in.
  2. lastArg() should return the last parameter passed in.

Examples

firstArg(1, 2, 3) ➞ 1

lastArg(1, 2, 3) ➞ 3

firstArg(8) ➞ 8

lastArg(8) ➞ 8

Notes

  • Return undefined if the function takes no parameters.
  • If the function only takes in one parameter, the firstArg and lastArg functions should return the same value.
  • JavaScript has an arguments object which keeps track of the parameters being passed in.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Nth Smallest Integer