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>>
C++ 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
std::map<std::string, std::vector<std::string>> splitByWarehouse(std::vector<Row> rows) {
}
Worked examples
| Call | Result |
|---|---|
splitByWarehouse(std::vector<Row>{Row{std::string("A1"), std::string("IST")}, Row{std::string("B2"), std::string("ANK")}, Row{std::string("C3"), std::string("IST")}}) | std::map<std::string, std::vector<std::string>>{{std::string("IST"), std::vector<std::string>{std::string("A1"), std::string("C3")}}, {std::string("ANK"), std::vector<std::string>{std::string("B2")}}} |
splitByWarehouse(std::vector<Row>{Row{std::string("A1"), std::string("IST")}}) | std::map<std::string, std::vector<std::string>>{{std::string("IST"), std::vector<std::string>{std::string("A1")}}} |
splitByWarehouse(std::vector<Row>{}) | std::map<std::string, std::vector<std::string>>{} |
splitByWarehouse(std::vector<Row>{Row{std::string("X"), std::string("IZM")}, Row{std::string("X"), std::string("IZM")}}) | std::map<std::string, std::vector<std::string>>{{std::string("IZM"), std::vector<std::string>{std::string("X"), std::string("X")}}} |
Hint
A map from code to a growing list. Create the list the first time you meet a code.
Reference solution in C++
std::map<std::string, std::vector<std::string>> splitByWarehouse(std::vector<Row> rows) {
std::map<string, std::vector<string>> result;
for (const auto& r : rows) result[r.warehouse].push_back(r.sku);
return result;
}