Skip to content

Instantly share code, notes, and snippets.

@breenie
Created February 15, 2019 12:59
Show Gist options
  • Select an option

  • Save breenie/190cfd2945801b70b1cf330c64c4f4bd to your computer and use it in GitHub Desktop.

Select an option

Save breenie/190cfd2945801b70b1cf330c64c4f4bd to your computer and use it in GitHub Desktop.
Buy x for y offer (2 for 3 for example)
const assert = require('assert');
function offer(x, y, itemsInBasket) {
return Math.ceil((itemsInBasket / x) * y);
}
assert.equal(offer(2, 1, 1), 1);
assert.equal(offer(2, 1, 3), 2);
assert.equal(offer(2, 1, 4), 2);
assert.equal(offer(2, 1, 5), 3);
assert.equal(offer(2, 1, 6), 3);
assert.equal(offer(3, 2, 1), 1);
assert.equal(offer(3, 2, 3), 2);
assert.equal(offer(3, 2, 2), 2);
assert.equal(offer(3, 2, 6), 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment