JavaScript for Beginners #57 Coding Challenge 10

preview_player
Показать описание
Here, we will look at another coding challenge. This coding challenge will involve the splice() array method, the slice() array method, and the forEach array method.

Coding Challenge:

//We will be given some arrays that hold the food dislikes for various people. We will also be given an array that holds all available food.
//Create a function that returns a list of foods that no one in the group objects to eating.
//Your function should not modify the original list of all available foods.
//Create a simple menu based on the list.
//Test Data 1:
const jennifer = ["Tacos", "Hamburgers", "Meatballs"];
const max = ["Tuna", "Veal", "Chicken"];
const menuItems = ["Eggrolls", "Chips with Salsa", "Pork Dippers", "Meatballs", "Tacos", "Salad", "Hamburgers", "Tuna", "Veal", "Pizza", "Chicken", "Fried Rice", "Pasta"];
//Test Data 2:
const ben = ["Eggrolls", "Salad", "Fried Rice"];

0:00 Instructions for the code challenge
1:55 Setting up a search and remove function
4:52 Setting up a function to get our updated foods list
7:28 Testing our function
9:15 Building a menu with forEach()

JavaScript Playlist:

MDN slice():

MDN splice():

MDN forEach():

MDN indexOf():
Рекомендации по теме
Комментарии
Автор

The second function to put the two arrays into one nested array does open my eyes, Thank you!
Gotta revisit from time to time.

chiuyinchan
Автор

The need of not modifying the menuItems arrray was the trickiest ;) In my solution, I concatenated all dislikes arrays into one and passed that array to a function similar to your modifyFoods function, there I made a shallow copy of the menuItems arrays, with all this said, I still like your solution more.

laponiec
Автор

Damn I just got to say thank you again I've been struggling with javascript for 2 weeks straight and these coding challenges really made the concepts of rest parameters and the foreach method click, especially since we have node to seamlessly double check our work.

chrisolo
Автор

This one was the first one that I could not make on my own, sadly. I hope I become more familiar with the logic as I continue to watch your videos. If you have a resource that has challenges like this, please recommend some! Thank you once again for everything you do :)

AnaRamirez-ngtj
join shbcf.ru