Deviopath › JavaScript

Swap First and Last

Easy · Arrays

Write a function swapFirstLast that returns a new array where the first and last elements have swapped places.

Arrays with fewer than 2 elements are returned as a copy without changes.

Next: Remove Duplicates