I am attempting to create a function that will take an array of numbers and generate a new array containing only the first and last elements from the input array.
However, I am encountering some challenges in getting the function to work properly with my current code.
let firstLast = [5, 10 ,15 ,20, 25, 30, 40];
firstLast.splice(1, firstLast.length - 2);
console.log(firstLast);
I envision being able to simply pass the array of numbers as a parameter when calling this function.