← Back to challenges

Return the First and Last Elements in an Array

JavaScriptHardarraysvalidationlanguage_fundamentals

Instructions

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(["innokodakademija", 13, null, false, true]) ➞ ["innokodakademija", true]

firstLast([undefined, 4, "6", "hello", null]) ➞ [undefined, null]

Notes

  • Test input will always contain a minimum of two elements within the array.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Flip the Boolean