mirror of https://github.com/01-edu/public.git
docs(manipulate-keys): correct grammar
This commit is contained in:
parent
8eea553805
commit
51a14fcbba
|
@ -2,40 +2,29 @@
|
||||||
|
|
||||||
### Instructions
|
### Instructions
|
||||||
|
|
||||||
I do not want onions. I want oranges!!!
|
I do not want onions. I want oranges.
|
||||||
|
|
||||||
Create 3 functions that works like the `.filter`, `.map` and `.reduce` array method but for the keys of your grocery cart.
|
Create 3 functions that works like the `.filter`, `.map` and `.reduce` array methods, but for the **keys** of your grocery cart. You can see their names and how they work in the examples.
|
||||||
|
|
||||||
- `filterKeys` filters the name of the items you have.
|
|
||||||
- `mapKeys` changes the name of the items you have.
|
|
||||||
- `reduceKeys` reducing you grocery cart.
|
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const nutrients = { carbohydrates: 12, protein: 20, fat: 5 }
|
const nutrients = { carbohydrates: 12, protein: 20, fat: 5 }
|
||||||
|
|
||||||
console.log(filterKeys(nutrients, (key) => /protein/.test(key)))
|
console.log(filterKeys(nutrients, (key) => /protein/.test(key)))
|
||||||
// output :
|
// output: { protein: 20 }
|
||||||
// { protein: 20 }
|
|
||||||
console.log(mapKeys(nutrients, (k) => `-${k}`))
|
console.log(mapKeys(nutrients, (k) => `-${k}`))
|
||||||
// output :
|
// output: { -carbohydrates: 12, -protein: 20, -fat: 5 }
|
||||||
// { -carbohydrates: 12, -protein: 20, -fat: 5 }
|
|
||||||
console.log(reduceKeys(nutrients, (acc, cr) =>acc.concat(', ', cr)))
|
console.log(reduceKeys(nutrients, (acc, cr) =>acc.concat(', ', cr)))
|
||||||
// output :
|
// output: carbohydrates, protein, fat
|
||||||
// carbohydrates, protein, fat
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Notions
|
|
||||||
|
|
||||||
- [devdocs.io/javascript/global_objects/array/filter](https://devdocs.io/javascript/global_objects/array/filter)
|
|
||||||
- [devdocs.io/javascript/global_objects/array/map](https://devdocs.io/javascript/global_objects/array/map)
|
|
||||||
- [devdocs.io/javascript/global_objects/array/reduce](https://devdocs.io/javascript/global_objects/array/reduce)
|
|
||||||
- [devdocs.io/javascript/global_objects/object/entries](https://devdocs.io/javascript/global_objects/object/entries)
|
|
||||||
- [devdocs.io/javascript/global_objects/object/fromentries](https://devdocs.io/javascript/global_objects/object/fromentries)
|
|
||||||
|
|
||||||
### Code provided
|
### Code provided
|
||||||
|
|
||||||
> all code provided will be added to your solution and doesn't need to be submited.
|
> The provided code will be added to your solution, and does not need to be submitted.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// small database with nutrition facts, per 100 grams
|
// small database with nutrition facts, per 100 grams
|
||||||
|
@ -51,3 +40,11 @@ const nutritionDB = {
|
||||||
orange: { calories: 49, protein: 0.9, carbs: 13, sugar: 12, fiber: 0.2, fat: 0.1 },
|
orange: { calories: 49, protein: 0.9, carbs: 13, sugar: 12, fiber: 0.2, fat: 0.1 },
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Notions
|
||||||
|
|
||||||
|
- [filter](https://devdocs.io/javascript/global_objects/array/filter)
|
||||||
|
- [map](https://devdocs.io/javascript/global_objects/array/map)
|
||||||
|
- [reduce](https://devdocs.io/javascript/global_objects/array/reduce)
|
||||||
|
- [entries](https://devdocs.io/javascript/global_objects/object/entries)
|
||||||
|
- [fromEntries](https://devdocs.io/javascript/global_objects/object/fromentries)
|
||||||
|
|
Loading…
Reference in New Issue