let dinnerFood = ['salad', 'soup', 'casserole']; let breakfastFood = ['omelet', 'pancakes', 'fruit']; console.log(`From array: ${breakfastFood}`); console.log(`To array: ${dinnerFood}`); function moveItem(itemToMove , fromArray, toArray) { if (fromArray.includes(itemToMove) && !toArray.includes(itemToMove)) { // we know the item is in the starting array function isItem(currentItem) { // if the two items are the same // then return the item to the caller return itemToMove === currentItem; } let theItem = fromArray.find(isItem); // ['salad', 'soup', 'casserole'] // ['salad', 'casserole'] // let start = dinnerFood.slice(0, 1) => ['salad'] // let end = dinnerFood.slice(2) => ['casserole'] let index = fromArray.indexOf(itemToMove); let start = fromArray.slice(0, index); let end = fromArray.slice(index + 1); fromArray = start.concat(end); toArray.push(theItem); return true } return false; } moveItem('pancakes', breakfastFood, dinnerFood); console.log(`From array: ${breakfastFood}`); console.log(`To array: ${dinnerFood}`);