Issue:
Develop a function that accepts an array as input and outputs a new array where the first and last elements are switched. The initial array will always be at least 2 elements long (for example, [1,5,10,-2] should result in [-2,5,10,1]).
Here is the code I have created:
function swapFirstAndLast(arr) {
var first = arr[0];
var last = arr[arr.length - 1];
console.log(first);
console.log(last);
// expected output is the array with the first and last elements swapped
}
swapFirstAndLast([1, 2, 3, 4]);
Is there anything I may be overlooking?