diff --git a/subjects/manipulate-keys/README.md b/subjects/manipulate-keys/README.md index 1b32ced0..19c764c9 100644 --- a/subjects/manipulate-keys/README.md +++ b/subjects/manipulate-keys/README.md @@ -10,6 +10,21 @@ Create 3 functions that works like the `.filter`, `.map` and `.reduce` array met - `mapKeys` changes the name of the items you have. - `reduceKeys` reducing you grocery cart. +### Examples + +```js +const nutrients = { carbohydrates: 12, protein: 20, fat: 5 } +console.log(filterKeys(nutrients, (key) => /protein/.test(key))) +// output : +// { protein: 20 } +console.log(mapKeys(nutrients, (k) => `-${k}`)) +// output : +// { -carbohydrates: 12, -protein: 20, -fat: 5 } +console.log(reduceKeys(nutrients, (acc, cr) =>acc.concat(', ', cr))) +// output : +// carbohydrates, protein, fat +``` + ### Notions - [devdocs.io/javascript/global_objects/array/filter](https://devdocs.io/javascript/global_objects/array/filter) diff --git a/subjects/manipulate-values/README.md b/subjects/manipulate-values/README.md index c9897422..256df972 100644 --- a/subjects/manipulate-values/README.md +++ b/subjects/manipulate-values/README.md @@ -11,7 +11,25 @@ Create 3 functions that works like the `.filter`, `.map` and `.reduce` array met - `filterValues` filters the values of your grocery cart. - `mapValues` changes the values of your grocery cart. -- `reduceValues` that will reduce your grocery cart. + +For the above function the callback function should accepts only the element in the arguments, this being the current element being processed. + +- `reduceValues` that will reduce your grocery cart. The callback function should accepts only the **accumulated value** and the **current value**. + +### Examples + +```js +const nutrients = { carbohydrates: 12, protein: 20, fat: 5 } +console.log(filterValues(nutrients, (nutrient) => nutrient <= 12)) +// output : +// { carbohydrates: 12, fat: 5 } +console.log(mapValues(nutrients, (v) => v+1)) +// output : +// { carbohydrates: 13, protein: 21, fat: 6 } +console.log(reduceValues(nutrients, (acc, cr) => acc + cr)) +// output : +// 37 +``` You will have a small database to help you with the groceries. @@ -25,7 +43,7 @@ You will have a small database to help you with the groceries. ### Code provided -> all code provided will be added to your solution and doesn't need to be submited. +> all code provided will be added to your solution and doesn't need to be submitted. ```js // small database with nutrition facts, per 100 grams