mirror of https://github.com/01-edu/public.git
docs(manipulate-entries): add usage section
This commit is contained in:
parent
0cb639701a
commit
722edd9e69
|
@ -8,7 +8,7 @@ Create 3 functions which work like the `.filter`, `.map` and `.reduce` array met
|
|||
- `mapEntries`: changes the key, the value or both.
|
||||
- `reduceEntries`: reduces the entries.
|
||||
|
||||
Create 3 additional functions that use your previously created functions:
|
||||
Create 3 additional functions that use your previously created functions and take an object as input:
|
||||
|
||||
- `totalCalories`: that will return the total calories of a cart.
|
||||
- `lowCarbs`: that leaves only those items which are lower than 50grams.
|
||||
|
@ -35,6 +35,58 @@ const nutritionDB = {
|
|||
}
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Here is a possible script to test your functions:
|
||||
|
||||
```js
|
||||
const groceriesCart = { orange: 500, oil: 20, sugar: 480 }
|
||||
|
||||
console.log('Total calories:')
|
||||
console.log(totalCalories(groceriesCart))
|
||||
console.log('Items with low carbs:')
|
||||
console.log(lowCarbs(groceriesCart))
|
||||
console.log('Total cart nutional facts:')
|
||||
console.log(totalCart(groceriesCart))
|
||||
```
|
||||
|
||||
And its output:
|
||||
|
||||
```console
|
||||
Total calories:
|
||||
2112.2
|
||||
Items with low carbs:
|
||||
{ oil: 20 }
|
||||
Total cart nutional facts:
|
||||
{
|
||||
orange: {
|
||||
calories: 245,
|
||||
protein: 4.5,
|
||||
carbs: 65,
|
||||
sugar: 45,
|
||||
fiber: 1,
|
||||
fat: 0.5
|
||||
},
|
||||
oil: {
|
||||
calories: 9.6,
|
||||
protein: 0,
|
||||
carbs: 0,
|
||||
sugar: 24.6,
|
||||
fiber: 0,
|
||||
fat: 30.2
|
||||
},
|
||||
sugar: {
|
||||
calories: 1857.6,
|
||||
protein: 0,
|
||||
carbs: 480,
|
||||
sugar: 480,
|
||||
fiber: 0,
|
||||
fat: 0
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Notions
|
||||
|
||||
- [filter](https://devdocs.io/javascript/global_objects/array/filter)
|
||||
|
|
Loading…
Reference in New Issue