// Here's the explanation of the challenge -- when you're done reading it,
// click on `main.js` above to get started with the challenge!
// It's time to make some _patatas bravas_ for our bar! But we just got a new
// batch of potatoes in, and we're not sure how many portions we can make
// using those potatoes. We'll figure this out with code!
// ## Description
// In this challenge, you will write a `makeBravas` function that receives a
// list (array) as an argument. Each element of the list is a string
// containing the word `"small"`, `"medium"` or `"large"`, representing a
// potato of that size.
// For example, if there is one large potato, one small potato and two medium
// potatoes, your function could be invoked like:
// makeBravas(["medium", "large", "small", "medium"])
// Your function should return the amount of complete portions of
// _patatas bravas_ that can be made with the given potatoes. Here's all you
// need to know about making _bravas_, the "secret recipe", if you will:
// A **small** potato can only be chopped into **four** potato chips.
// A **medium** potato can be chopped into **eight** potato chips.
// A **large** potato can be chopped into **twenty-four** potato chips!
// To make a **portion** of _patatas bravas_, you need **twenty** potato chips.
// Any potato chips that remain after the complete portions are made are
// discarded. For example, given one large potato, your function should return
// exactly one (`1`), as you can only make one portion -- the four leftover
// chips are ignored.
/* Check out README.md for instructions! */
function makeBravas(potatoes) {
/* Your code goes here! */
/* Press [▶ Run] to see your code in action! */
/* You'll see the output of the tests below the button */
}
/* Test runner (do not modify this line!) */
const expect = require("./expect")(makeBravas)
/* Test cases (remember to add more!) */
// no potatoes, no bravas!
expect(0, [])
// one large potato gives you one portion
expect(1, ["large"])
// your test case here!
// expect(expectedPortions, potatoes)
/* Test runner (do not modify this!) */
module.exports = (run) => function expect(expected, ...inputs) {
const stringify = (value) => {
const serialised = JSON.stringify(value, undefined, 2)
|| "undefined"
const lines = serialised.split('\n')
for (i = 1; i < lines.length; i++) {
lines[i] = "\t" + lines[i]
}
return lines.join('\n')
}
const serialisedInputs = inputs
.map(stringify)
.join(", ")
const actual = run(...inputs)
if (expected !== actual) {
console.log(
` ❌ ${run.name}(${serialisedInputs})\n\n` +
`\texpected: ${stringify(expected)}\n` +
`\tbut instead got: ${stringify(actual)}\n\n`
)
} else {
console.log(
` ✅ ${run.name}(${serialisedInputs}) === ${stringify(actual)}\n`
)
}
}