/*
Callback Methods
*/
// const util = {
// findBurgRating: function(singleFeedback) {
// return singleFeedback.comment.includes('burg');
// }
// }
// function findBurgRating(singleFeedback, index, array) {
// return singleFeedback.comment.includes('burg')
// }
//rating => rating.comment.includes('burg')
// find the first rating that talks about a burger with find()
// const burgRating = feedback.find(findBurgRating);
// console.log(burgRating);
function findByWord(word) {
return function(singleFeedback) {
return singleFeedback.comment.includes(word);
}
}
const wordFinder = findByWord('Smoothie');
const findWord = feedback.find(wordFinder);
console.log(findWord);
// find all ratings that are above 2 with filter()
function filterByMinRating(minRating) {
return function (singleFeedback) {
return singleFeedback.rating > minRating;
}
}
const goodReviews = feedback.filter(filterByMinRating(4));
console.table(goodReviews)
// find all ratings that talk about a burger with filter()
const burgRatings = feedback.filter(singleFeedback => singleFeedback.comment.includes('burg'));
console.table(burgRatings)
// Remove the one star rating however you like!
// Para mostrar solamente los que son superiores a 1. Esto puede ser para un dropdown donde elijas los ratings de que numero para arriba o abajo quieres ver.
const legitRatings = feedback.filter(single => single.rating !== 1);
console.table(legitRatings);
// check if there is at least 5 of one type of meat with some()
// Cuando quieres saber si hay por lo menos un numero de algo. GIves a boolean.
const isThereEnoughOfAtLeastOneMeat = Object.values(meats).some(meatValue => meatValue >= 5);
console.log(isThereEnoughOfAtLeastOneMeat);
// make sure we have at least 3 of every meat with every()
// Cuando quieres saber si hay por lo menos un numero de TODO. GIves a boolean.
const isThereEnoughOfEvery = Object.values(meats).every(meatValue => meatValue >= 3);
console.log(isThereEnoughOfAtLeastOneMeat);
// sort the toppings alphabetically with sort()
const numbers = [1,2,100,3,200,400,155]
// const numbersSorted = numbers.sort(function(firstItem, secondItem) {
// if(firstItem > secondItem) {
// return 1;
// } else if(secondItem > firstItem) {
// return -1;
// } else {
// return 0;
// }
// });
const numbersSorted = numbers.sort(function(firstItem, secondItem) {
return firstItem - secondItem; //in forward order
// return secondItem - firstItem; //in inverse order
});
console.log(numbersSorted);
// sort the order totals from most expensive to least with .sort()
function numberSort(a, b) {
return b - a;
}
console.log(orderTotals.sort(numberSort));
// Sort the prices with sort()
const productsSortedByPrice = Object.entries(prices).sort(function(a, b) {
const aPrice = a[1];
const bPrice = b[1]
return bPrice - aPrice;
});
console.table(productsSortedByPrice);