diff --git a/filter/ex1.js b/filter/ex1.js index fa4f3d80..dbc12a8d 100644 --- a/filter/ex1.js +++ b/filter/ex1.js @@ -13,7 +13,9 @@ Expected OUTPUT for this sample: */ + function getPositiveNumbers(numbers) { + return numbers.filter(numbers => numbers >= 0) } // If you need, you can always visualize the result with a console.log. diff --git a/filter/ex2.js b/filter/ex2.js index 5bc423e3..55488d8d 100644 --- a/filter/ex2.js +++ b/filter/ex2.js @@ -26,7 +26,9 @@ Expected OUTPUT for this sample: */ function keepStarks(names) { -} + return names.filter(names => names.endsWith('Stark') + + )} // DON'T TOUCH THIS! module.exports = keepStarks; diff --git a/filter/ex3.js b/filter/ex3.js index 1076cf80..9a234bd2 100644 --- a/filter/ex3.js +++ b/filter/ex3.js @@ -33,6 +33,10 @@ Expected OUTPUT for these sample arguments: */ function filterOnPrice(products, maxPrice) { + + return products.filter(price => price.price <= maxPrice) + + } // DON'T TOUCH THIS! diff --git a/map/ex1.js b/map/ex1.js index 323e1028..e3543d84 100644 --- a/map/ex1.js +++ b/map/ex1.js @@ -25,8 +25,17 @@ Expected OUTPUT for this sample array: ] */ +const words = ['Chicken', 'Bacon', 'Tofu', 'Mayonnaise']; + + function getStringsLength(strings) { + return strings.map(function(words){ + return words + ' contains ' + words.length + ' characters'; + + }); + + } // If you need, you can always visualize the result with a console.log. diff --git a/map/ex2.js b/map/ex2.js index 99a2a2f1..51d778cc 100644 --- a/map/ex2.js +++ b/map/ex2.js @@ -32,6 +32,8 @@ Sample foods array, i.e. INPUT: } ] + + Expected OUTPUT for this sample [ 'Bacon is not suitable for vegetarians', @@ -43,9 +45,19 @@ Expected OUTPUT for this sample */ function getFoodCategories(foods) { -} + return foods.map(aliment => { + if (aliment.isVegetarian === true){ + return (aliment.food + ' is suitable for vegetarians') + + } else { + return (aliment.food + ' is not suitable for vegetarians') + } + }) +} + + // DON'T TOUCH THIS! module.exports = getFoodCategories; diff --git a/map/ex3.js b/map/ex3.js index 6a1c5960..6512928d 100644 --- a/map/ex3.js +++ b/map/ex3.js @@ -61,10 +61,20 @@ Expected OUTPUT for this sample: */ + function getMoviesFreshness(movies) { + return movies.map(movie => { + if (movie.rating < 60){ + movie.label = 'rotten' + } else if (movie.rating >= 60 && movie.rating <= 75){ + movie.label = 'fresh' + } else { + movie.label = 'certified fresh' + } + return movie + }) } - // DON'T TOUCH THIS! module.exports = getMoviesFreshness;