Skip to content

Commit

Permalink
Add solution for the-vampiire#68 in javascript. (the-vampiire#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain1811 authored and the-vampiire committed Oct 8, 2019
1 parent e0cf800 commit dfcfce8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions javascript/intermediate/multiple-cash-registers_sylvain1811.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Hacktoberithms - Multiple Cash Registers
* https://github.com/the-vampiire/hacktoberithms/issues/68
* By sylvain1811, 7 oct 2019
* node version v12.9.1
*/

function checkout_time(customers, n_cashier) {
let cashiers = Array(n_cashier).fill(0)
customers.forEach(customer => {
minIndex = cashiers.reduce((accIdx, current, index) => {
return current < cashiers[accIdx] ? index : accIdx
}, 0)
cashiers[minIndex] = cashiers[minIndex] + parseInt(customer)
});
return Math.max(...cashiers)
}

function test() {
cases = [
[[[5, 1, 3], 1], 9],
[[[10, 3, 4, 2], 2], 10]
]
result = cases.reduce((acc, current, idx) => {
res = checkout_time(...current[0])
console.log("[Test case", idx, "] Inputs are ", current[0],
", expected result is ", current[1],
", result is ", res,
" : ", res == current[1] ? "PASS" : "FAILED");
return acc && res == current[1]
}, true)
result ? console.log("All tests passed") : console.log("Some tests failed")
}

test()

0 comments on commit dfcfce8

Please sign in to comment.