So I need to return the middle item of an array (if there is odd number of items), pretty easy:
function middleItem(oddArr) {
let count = 0;
if (arr.length % 2 !== 0) {
for (i = 0; i < arr.length; i++) {
arr[i] === arr[(arr.length - 1) / 2] && (count = arr[i]);
}
}
return count
}
But when it comes to return the middle two items from an array with even number of items, I start lose my mind lol. I search for 2 hours without looking for an answer (I need to improve my logic) but now I would love to know what you guys think is the best method to do it. Many thanks !
function middleItem(evenArr) {
}