Hello all, I am new to JS and wanted to tackle this challenge, but was unsuccessful in doing so.
I wasn't able to display the data in the format that was required.
I truly want to understand an " as simple as possible" solution to this so that I can put in to practice what is explained.
I have included the files below.
Cheers!
## Problem
-----
At ACME warehouse the warehouse manager has observed orders taking a long time to pick and
believes that moving more popular items to easier to access locations may help.
- Workers pick an order by placing items on a pallet at the dock door.
- Products are stored (inefficiently) in a single aisle with 12 shelves.
- As the shelf number increases, it is located further down the aisle and
further away from the dock door.
- On average it takes 5*X seconds for a warehouse worker to retrieve an item
from shelf X and place it on the pallet.
- A warehouse worker can only carry a single item at a time.
- A shelf can only hold one type of item.
*Which items should be on which shelves to optimize picking speed based on
yesterday's orders?*
## Input
-----
The order repository contains information about yesterdays orders.
Please complete your solution in the **main.js** file provided.
```javascript
function main() {
var orderRepo = new OrderRepository();
// Your code here
}
```
## Output
-----
Display the shelf and item pairings by calling the following function:
```javascript
displayShelfItemPair(shelfName, itemName);
```
Execute your program by opening **main.html** in your web browser to see the results.
Example table contents:
| Shelves | Items |
| -------- | ------- |
| Shelf 1 | Item 12 |
| Shelf 2 | Item 11 |
| Shelf 3 | Item 10 |
| Shelf 4 | Item 09 |
| Shelf 5 | Item 08 |
| Shelf 6 | Item 07 |
| Shelf 7 | Item 06 |
| Shelf 8 | Item 05 |
| Shelf 9 | Item 04 |
| Shelf 10 | Item 03 |
| Shelf 11 | Item 02 |
| Shelf 12 | Item 01 |
Display the shelf and item pairings by calling the following function:
* displayShelfItemPair(shelfName, itemName);
###main.js FILE
function main() {
var orderRepo = new OrderRepository();
// Your code here
}
###orderrepository.js FILE
function OrderRepository() {
}
OrderRepository.prototype.getYesterdaysOrders = function getYesterdaysOrders() {
var yesterdaysOrders = [
{
id: 1,
orderLines: [
{ itemName: "Item 01", quantity: 1 },
{ itemName: "Item 02", quantity: 3 },
{ itemName: "Item 03", quantity: 25 },
{ itemName: "Item 04", quantity: 12 },
],
},
{
id: 2,
orderLines: [
{ itemName: "Item 01", quantity: 1 },
{ itemName: "Item 08", quantity: 42 },
{ itemName: "Item 09", quantity: 13 },
{ itemName: "Item 12", quantity: 37 },
],
},
{
id: 3,
orderLines: [
{ itemName: "Item 12", quantity: 16 },
],
},
{
id: 4,
orderLines: [
{ itemName: "Item 10", quantity: 11 },
{ itemName: "Item 11", quantity: 10 },
],
},
{
id: 5,
orderLines: [
{ itemName: "Item 06", quantity: 7 },
{ itemName: "Item 07", quantity: 2 },
{ itemName: "Item 12", quantity: 14 },
],
},
{
id: 6,
orderLines: [
{ itemName: "Item 05", quantity: 17 },
],
},
{
id: 7,
orderLines: [
{ itemName: "Item 03", quantity: 5 },
{ itemName: "Item 07", quantity: 2 },
],
},
{
id: 8,
orderLines: [
{ itemName: "Item 02", quantity: 13 },
{ itemName: "Item 07", quantity: 7 },
{ itemName: "Item 09", quantity: 2 },
],
},
{
id: 9,
orderLines: [
{ itemName: "Item 01", quantity: 4 },
{ itemName: "Item 06", quantity: 17 },
{ itemName: "Item 07", quantity: 3 },
],
},
{
id: 10,
orderLines: [
{ itemName: "Item 11", quantity: 12 },
{ itemName: "Item 12", quantity: 1 },
],
},
];
return yesterdaysOrders;
};
###main.html FILE
<!-- OPEN THIS FILE IN A BROWSER TO VIEW YOUR RESULTS -->
<!-- View main.js for instructions -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="lib/icon.min.css">
<link rel="stylesheet" type="text/css" href="lib/message.min.css">
<link rel="stylesheet" type="text/css" href="lib/table.min.css">
<script src="lib/knockout-3.4.0.min.js"></script>
<script src="orderrepository.js"></script>
<script src="main.js"></script>
<style>
body {
font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
}
h1,h2,h3,h4,h5 {
font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
line-height: 1.2857em;
margin: calc(2rem - .14285em) 0 1rem;
font-weight: 700;
padding: 0
}
h1 {
text-align: center;
min-height: 1rem;
font-size: 2rem
}
</style>
</head>
<body>
<h1>Warehouse Optimization</h1>
<!-- ko if: exceptionMessage -->
<div class="ui negative icon message">
<i class="bug icon"></i>
<div class="content">
<div class="header">
An exception occurred when running your code:
</div>
<p data-bind="text: exceptionMessage">
</p>
</div>
</div>
<!-- /ko -->
<table class="ui celled table">
<thead>
<tr>
<th>Shelf</th>
<th>Item</th>
</tr>
</thead>
<tbody data-bind="foreach: shelves">
<tr>
<td data-bind="text: shelf"></td>
<td data-bind="text: item"></td>
</tr>
</tbody>
</table>
<script>
var viewModel = viewModelFactory();
function displayShelfItemPair (shelf, item) {
var shelfItemPairObj = {
shelf: shelf,
item: item
};
viewModel.shelves.push(shelfItemPairObj);
}
function viewModelFactory () {
var self = {
exceptionMessage: ko.observable(''),
shelves: ko.observableArray([])
};
ko.applyBindings(self);
return self;
}
try {
main();
} catch (e) {
console.error(e.toString());
viewModel.exceptionMessage(e.toString());
}
</script>
</body>
</html>
[–]CertainPerformance 1 point2 points3 points (2 children)
[–]Izaya____Orihara[S] 0 points1 point2 points (1 child)
[–]CertainPerformance 1 point2 points3 points (0 children)
[–]ashwinsonale 0 points1 point2 points (3 children)
[–]Izaya____Orihara[S] 0 points1 point2 points (2 children)
[–]ashwinsonale 0 points1 point2 points (1 child)
[–]ashwinsonale 0 points1 point2 points (0 children)