Return First and Last Parameter

Published by Helen Yu in

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. Check the Resources tab to learn more.
Watch a quick demo on how Edabit works.