From 984227e4ecac3e2f552b119a3cc37cf3bbeb6c71 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jan 2022 18:34:19 +0000 Subject: [PATCH] fix to manipulate-key --- subjects/manipulate-keys/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/subjects/manipulate-keys/README.md b/subjects/manipulate-keys/README.md index 1b32ced0d..19c764c9d 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)