Created
February 15, 2019 12:59
-
-
Save breenie/190cfd2945801b70b1cf330c64c4f4bd to your computer and use it in GitHub Desktop.
Buy x for y offer (2 for 3 for example)
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 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