Return the First and Last Elements in an Array

Published by Pickle in

Create a function that takes an array of values and returns the first and last values in a new array.

Examples

firstLast([5, 10, 15, 20, 25]) ➞ [5, 25]

firstLast(["edabit", 13, false, true]) ➞ ["edabit", true]

firstLast(["hello", "edabit", "dot", "com"]) ➞ ["hello", "com"]

Notes

  • Test input will always contain a minimum of two elements within the array.
  • Don't forget to return the result.
  • If you get stuck on a challenge, find help in the Resources tab.
  • If you're really stuck, unlock solutions in the Solutions tab.
Watch a quick demo on how Edabit works.