mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-05 21:04:28 +08:00
fix: add groupByZone output shape description and test cases (#67783)
Signed-off-by: Kriti Dogra <kritidogra1808@gmail.com>
This commit is contained in:
parent
590041e2bf
commit
c69fa6db9b
@ -31,7 +31,7 @@ The `rawData` array contains pipe-separated strings with the format `sku|name|qt
|
||||
- Otherwise, if the shipment item's `sku` already exists in the pantry, the action `type` should be `"restock"`.
|
||||
- Otherwise (the shipment item's `sku` does not exist in the pantry), the action `type` should be `"donate"`.
|
||||
|
||||
3. You should implement a `groupByZone(actions)` function that groups the actions into storage zones based on each item’s `zone` property.
|
||||
3. You should implement a `groupByZone(actions)` function that groups the actions into storage zones based on each item's `zone` property. The function should return an object where each key is a zone name and the value is an array of actions belonging to that zone. For example, if actions contain items with zones `"fridge"` and `"pantry"`, the result should be `{ fridge: [...], pantry: [...] }`.
|
||||
|
||||
4. You should implement a `clonePantry(pantry)` function that returns a deep copy of the pantry so planning changes do not affect the original list. A deep copy means creating a new array with new objects, so modifying the copy does not change the original pantry.
|
||||
|
||||
@ -181,6 +181,23 @@ assert.isArray(result.fridge);
|
||||
assert.isArray(result.pantry);
|
||||
```
|
||||
|
||||
Your `groupByZone` function should correctly group actions with the right content and count.
|
||||
|
||||
``` js
|
||||
const actions = [
|
||||
{ type: "restock", item: { sku: "A1", zone: "fridge" } },
|
||||
{ type: "donate", item: { sku: "B1", zone: "fridge" } },
|
||||
{ type: "discard", item: { sku: "C1", zone: "pantry" } },
|
||||
];
|
||||
|
||||
const result = groupByZone(actions);
|
||||
|
||||
assert.lengthOf(result.fridge, 2);
|
||||
assert.lengthOf(result.pantry, 1);
|
||||
assert.strictEqual(result.fridge[0].item.sku, "A1");
|
||||
assert.strictEqual(result.pantry[0].type, "discard");
|
||||
```
|
||||
|
||||
You should define a function named `clonePantry` that accepts one parameter called `pantry`.
|
||||
|
||||
``` js
|
||||
|
||||
Loading…
Reference in New Issue
Block a user