sorry if this doesn't make sense. Im very, very new to this.
I am trying to solve a problem where it returns the First and Last value of an array. I feel like I have got the foundations right with this code. e.g:
function getFirstAndLast(array) {
return [array.shift(), array.pop()]
}
let newArray = []
newArray = getFirstAndLast([5, 10])
console will print: [5, 10]
However, when given just 1 argument the console will return the value and undefined. e.g:
function getFirstAndLast(array) {
return [array.shift(), array.pop()]
}
let newArray = []
newArray = getFirstAndLast([5])
console will now print: [5, undefined]
Question is how do I change my code to only return the single value without the undefined but still retain the ability to pull the First and Last array value if given 2 or more arguments.
again sorry if this makes no sense or if i have mistakenly called something wrong. Thanks