dang it!! ): I guess my brain can’t see what the problem is. the error message literally doesn’t make any sense. How can you put only the first five by default if the length is more than the array? I don’t get it?
function first(arr, n) {
const myArray = [];
if (n == undefined) {
myArray.push(arr[0]);
return myArray;
}
if (n < arr.length) {
return []
}
for (let i = 0; i < n; i++) {
myArray.push(arr[i]);
}
return myArray;
console.log(myArray);
}
You sure you have the syntax right for if n is larger then arr.length? And would they want an empty array in that case as well?
But the slice method i think is a better way to go overall. The test even gives a little bit of a hint on how to handle n if there is only one argument given.