-
-
Save junerockwell/ee516771dc42d08a3016 to your computer and use it in GitHub Desktop.
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
var assert = require('assert'); | |
/******************************** | |
* We want make a package of goal kilos of skittles. We have | |
* inventory of small bags (1 kilos each) and big bags (5 kilos each). | |
* Return the number of small bags to use, assuming we always | |
* use big bags before small bags. Return -1 if it can't be done. | |
* | |
* See the asserts below for examples of input | |
* and expected output. | |
* | |
* If you have node installed, all you need to do to test | |
* your code is run: `node skittles.js`. If you see errors, | |
* it is because the tests below did not pass. Once the | |
* tests do pass, you will see a log of `Success!` | |
* | |
* YOUR CODE BELOW HERE | |
********************************/ | |
function createPackage(small, big, goal) { | |
var big *= 5; | |
if ( big > goal ) { | |
return 0; | |
} | |
else if ( big < goal ) { | |
var needmore = goal - big; | |
var smallsneed = needmore - small; | |
return smallneed; | |
} else { | |
return -1; | |
} | |
} | |
/******************************** | |
* YOUR CODE ABOVE HERE | |
********************************/ | |
assert.equal( | |
createPackage(4, 1, 9), | |
4 | |
); | |
assert.equal( | |
createPackage(4, 1, 10), | |
-1 | |
); | |
assert.equal( | |
createPackage(4, 1, 7), | |
2 | |
); | |
assert.equal( | |
createPackage(6, 2, 7), | |
2 | |
); | |
assert.equal( | |
createPackage(4, 1, 5), | |
0 | |
); | |
assert.equal( | |
createPackage(4, 1, 4), | |
4 | |
); | |
assert.equal( | |
createPackage(5, 4, 9), | |
4 | |
); | |
assert.equal( | |
createPackage(9, 3, 18), | |
3 | |
); | |
console.log('Success!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment