Hello! My name is Rick and I am currently enrolled in a coding bootcamp.
This past December I finished up a year long study with a full-stack school in NYC called [Codeimmersives] (https://www.codeimmersives.com/). We explored HTML, CSS, JavaScript, and how to build applications using the MERN stack. I learned about class-based components, passing props around (prop-drilling) and utilizing the component lifecycle(componentWillMount, componentDidMount, etc). After learning class based components, we moved on to functional based components using hooks, custom hooks, and different ways to manage state, such as the useContext and Redux APIs. (This is just a brief overview of the technologies I studied over the past year). Currently I am enrolled at devCodeCamp learning about Python, Django and reviewing what I already know about JavaScript. I am documenting my journey by sharing these blog posts and what I'm currently working on. Feel free to comment below!
Higher Order Functions
In Javascript, functions can be assigned to variables in the same way that strings or arrays can. They can be passed into other functions as parameters or returned from them as well.
A “higher-order function” is a function that accepts functions as parameters and/or returns a function.
These are the problems I solved today:
let dishes = [
{
"id": 1,
"name": "Pizza",
"cuisine": "Italian",
"servings": 8,
"ingredients": ["tomato", "cheese"]
},
{
"id": 2,
"name": "Spaghetti",
"cuisine": "Italian",
"servings": 2,
"ingredients": ["tomato", "cheese"]
},
{
"id": 3,
"name": "Ravioli",
"cuisine": "Italian",
"servings": 2,
"ingredients": ["tomato", "cheese"]
},
{
"id": 4,
"name": "Enchiladas",
"cuisine": "Mexican",
"servings": 6,
"ingredients": ["tomato", "cheese"]
},
{
"id": 5,
"name": "Tacos",
"cuisine": "Mexican",
"servings": 4,
"ingredients": ["tomato", "cheese"]
},
{
"id": 6,
"name": "Burrito Supreme",
"cuisine": "Mexican",
"servings": 1,
"ingredients": ["tomato", "cheese"]
},
{
"id": 7,
"name": "Elote",
"cuisine": "Mexican",
"servings": 4,
"ingredients": ["corn", "cheese"]
},
{
"id": 8,
"name": "Crepes",
"cuisine": "French",
"servings": 1,
"ingredients": ["flour", "sugar"]
},
{
"id": 9,
"name": "Corned Beef & Cabbage",
"cuisine": "Irish",
"servings": 10,
"ingredients": ["beef", "cabbage"]
},
{
"id": 10,
"name": "Beef Stew",
"cuisine": "Irish",
"servings": 8,
"ingredients": ["beef", "tomato"]
},
{
"id": 11,
"name": "Lasagna",
"cuisine": "Vegetarian",
"servings": 8,
"ingredients": ["tomato", "cheese"]
},
{
"id": 12,
"name": "Falafel",
"cuisine": "Vegetarian",
"servings": 1,
"ingredients": ["chickpea", "parsley"]
},
{
"id": 13,
"name": "Chili",
"cuisine": "Vegetarian",
"servings": 13,
"ingredients": ["tomato", "chickpea"]
},
{
"id": 14,
"name": "Goulash",
"cuisine": "Hungarian",
"servings": 15,
"ingredients": ["beef", "tomato"]
},
]
function findMexicanFood(){
let results = dishes.filter(function(el){
if(el.cuisine === "Mexican"){
return true;
}
else{
return false;
}})
return results;
}
let mexicanFood = findMexicanFood();
console.log('Mexican Foods: ', mexicanFood)
function problemOne(){
let results = dishes.filter(dish => dish.cuisine === "Vegetarian")
return results;
}
let vegetarianDishes = problemOne();
console.log('Vegitarian Dishes:', vegetarianDishes)
function problemTwo(){
let results = dishes.filter(dish => dish.cuisine === "Italian" && dish.servings > 5)
return results;
}
let italianMoreThanFive = problemTwo();
console.log('ItalianMorThanFive Dishes:', italianMoreThanFive)
function problemThree(){
let results = dishes.filter(dish => dish.id === dish.servings)
return results;
}
let dishIdMatchesServingCount = problemThree();
console.log('dishIdMatchesServingCount Dishes:', dishIdMatchesServingCount)
function problemFour(){
let results = dishes.filter(dish => dish.servings %2 === 0)
return results;
}
let evenServingCount = problemFour();
console.log('evenServingCount Dishes:', evenServingCount)
function problemFive(){
let results = dishes.filter(dish => dish.ingredients[0]==="tomato" && dish.ingredients[1] === "cheese")
return results;
}
let tomatoCheese = problemFive();
console.log('tomatoCheese Dishes:', tomatoCheese)
function problemSix(){
let result = dishes.map((dish)=> dish.cuisine).filter((item, i, arr)=> arr.indexOf(item) === i)
return result
}
let cuisines = problemSix();
console.log('cuisine Dishes:', cuisines)
function problemEight(){
let result = dishes.filter(dish => dish.cuisine === "Vegetarian").map(dish => dish.name = `${dish.cuisine} ${dish.name}`)
return result
}
let appendedNamesTwoVegetarian = problemEight();
console.log('appendedName2 Dishes:', appendedNamesTwoVegetarian)
function problemNine(){
let result = dishes.filter(dish => dish.ingredients.includes("chickpea"))
return result
}
let chickpeaIngredients = problemNine();
console.log('chickpeaIngredients Dishes:', chickpeaIngredients)
function problemTen(){
let result = dishes.map((dish)=> dish.servings).reduce((total, curr) => curr + total)
return result
}
let servingCount = problemTen();
console.log('servingCount Dishes:', servingCount)
function problemEleven(){
let freq = {}
cuisines = dishes.map((dish)=>dish.cuisine)
for(cuisine of cuisines){
if(freq[cuisine]){
freq[cuisine] += 1
}else freq[cuisine] = 1
}
let result = dishes.filter((dish)=> freq[dish.cuisine] === 1)
return result
}
let uniqueCuisineTypes = problemEleven();
console.log('uniqueCuisineTypes Dishes:', uniqueCuisineTypes)