Split an order across warehouses
Fulfilment needs the order regrouped by the warehouse each line ships from, so it can raise one pick list per site.
- Group the SKUs under their warehouse code.
- Within a warehouse, keep the order the lines arrived in.
- A warehouse with no lines does not appear at all.
splitByWarehouse(rows: list<Row>) → map<string, list<string>>
Go needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
func splitByWarehouse(rows []Row) map[string][]string {
}
Worked examples
| Call | Result |
|---|---|
splitByWarehouse([]Row{Row{Sku: "A1", Warehouse: "IST"}, Row{Sku: "B2", Warehouse: "ANK"}, Row{Sku: "C3", Warehouse: "IST"}}) | map[string][]string{"IST": []string{"A1", "C3"}, "ANK": []string{"B2"}} |
splitByWarehouse([]Row{Row{Sku: "A1", Warehouse: "IST"}}) | map[string][]string{"IST": []string{"A1"}} |
splitByWarehouse([]Row{}) | map[string][]string{} |
splitByWarehouse([]Row{Row{Sku: "X", Warehouse: "IZM"}, Row{Sku: "X", Warehouse: "IZM"}}) | map[string][]string{"IZM": []string{"X", "X"}} |
Hint
A map from code to a growing list. Create the list the first time you meet a code.
Reference solution in Go
func splitByWarehouse(rows []Row) map[string][]string {
result := map[string][]string{}
for _, r := range rows {
result[r.Warehouse] = append(result[r.Warehouse], r.Sku)
}
return result
}