using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const atm = (value, banknotes, count = 0, bestCount = -1) => { | |
const filteredBankNotes = banknotes.filter(note => note <= value); | |
for (let i = 0; i < filteredBankNotes.length; i++) { | |
if (filteredBankNotes[i] <= value) { | |
count++; | |
value -= filteredBankNotes[i]; | |
if (bestCount !== -1 && count > bestCount) { | |
break; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const buckets = (buckets) => { | |
let sum = 0; | |
let times = 0; | |
for (let i = Math.min(...buckets); i < Math.max(...buckets); i++) { | |
let start = false; | |
let subTotal = 0; | |
for (const bucket of buckets) { |