From 74a598290d5262d0ab9e10bb1fe8b133e5d27d0c Mon Sep 17 00:00:00 2001 From: Olusegun Opalanwo Date: Thu, 16 Nov 2023 22:06:55 +0100 Subject: [PATCH 1/3] name added --- Contributors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Contributors.md b/Contributors.md index a9e9ede..4db6151 100644 --- a/Contributors.md +++ b/Contributors.md @@ -5,4 +5,5 @@ 1. icodejsx 2. ogbon(Segun Amosu) 3. Solomon Eseme +4. Olusegun From 4e6eeca6cda854d20847a631f05802c755693845 Mon Sep 17 00:00:00 2001 From: Olusegun Opalanwo Date: Thu, 16 Nov 2023 22:28:24 +0100 Subject: [PATCH 2/3] map,filter,reducer --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 79a6b67..c4f2355 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ # -100daysofEngineering- Repo for Mastering Backend BootCamp and #100daysOfEngineering +Assignment :create an elaborate examples about map reduce filter and share it on github +1. map() function is a function that transforms through the elements of an array and performs a given calculation/function on eahc of the elements and then creates a new array containing the results of the calculation on each element. +Example: +Asumme we have an array of prices and we want to increase each element by mutliple of 2 and save the new prices in another array + let prices = [1.5,2,5,6.5,10]; + let newPrices = prices.map((price)=>price*2); + newPrices now contains the value of the elements of the first array doubled. +2. filter() function is used to get the element of an array that meets a condition. We can use it like a custom search function in an array, retuning all the elements that matches what we are searching for. +Example: +Using the prices array we declared earlier, we can search for all the prices that are not more than 5 using filter() + let notMoreThan5 = prices.filter((price)=>price<5); +3. reduce() function, unlike the first two methods, returns a single value which is the result of reducing the elements of the array using a function we specified. The value returned is the reducer +Example: +Let say we want to find the total price of commodities from the prices array. Instead of looping through the array manually, adding each of the elements, we can use reducer + let totalPrice = price.reduce((total,currentPriceToAdd)=>total + currentPriceToAdd, 0); + +The difference between these functions are glaring: +Only map and filter returns new array from the calculation/check we specified. Redurce on the other hand only accummulates the result of calculation on each of the elements of the array, and returns a single value. From 1c9b328dc6df781a2434e39f9c03d9ce57f88de8 Mon Sep 17 00:00:00 2001 From: Olusegun Opalanwo Date: Thu, 16 Nov 2023 22:29:50 +0100 Subject: [PATCH 3/3] map, filter and reduce spacing --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c4f2355..75156b8 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,19 @@ Repo for Mastering Backend BootCamp and #100daysOfEngineering Assignment :create an elaborate examples about map reduce filter and share it on github 1. map() function is a function that transforms through the elements of an array and performs a given calculation/function on eahc of the elements and then creates a new array containing the results of the calculation on each element. + Example: Asumme we have an array of prices and we want to increase each element by mutliple of 2 and save the new prices in another array let prices = [1.5,2,5,6.5,10]; let newPrices = prices.map((price)=>price*2); newPrices now contains the value of the elements of the first array doubled. 2. filter() function is used to get the element of an array that meets a condition. We can use it like a custom search function in an array, retuning all the elements that matches what we are searching for. + Example: Using the prices array we declared earlier, we can search for all the prices that are not more than 5 using filter() let notMoreThan5 = prices.filter((price)=>price<5); 3. reduce() function, unlike the first two methods, returns a single value which is the result of reducing the elements of the array using a function we specified. The value returned is the reducer + Example: Let say we want to find the total price of commodities from the prices array. Instead of looping through the array manually, adding each of the elements, we can use reducer let totalPrice = price.reduce((total,currentPriceToAdd)=>total + currentPriceToAdd, 0);