Challenge: Proper burgers

Run Settings
LanguageJavaScript
Language Version
Run Command
// Here's the explanation of the challenge -- when you're done reading it, // click on `main.js` above to get started with the challenge! // Here at Nirvana Burgers, our burgers are very simple, but delicious -- // and yet, our new chef keeps messing them up somehow! We don't have time // for another metaphysical kitchen debate on what constitutes a proper // burger, so we'll have to settle the matter with code. // ## Description // In this challenge, you will write a `isProperBurger` function that receives // a list (array) as an argument. Each element of the list is a string // containing the name of an ingredient. Together, the list represents the // whole stack of ingredients in the burger, ordered from bottom to top -- // in the order you'd put them on the plate. // For example, for a simple cheese burger, your function could be invoked // like: // isProperBurger( // ["bread", "patty", "cheese", "bread"]) // Your function should return a boolean (`true` or `false`) that represents // whether the burger is properly made. Here's all you need to know about the // art of making proper burgers: // - A burger always starts and ends with `"bread"`. There should not be // bread anywhere else in the burger. // - There has to be **at least one** `"patty"` **in between** the two pieces // of bread. If there's no patty, then it's not a burger, it's just a pile of // bread. // There cannot be `"cheese"` under the patties. Cheese always goes on top // (that is, on the list, it must appear _after_ the patties) // Our burgers really are simple -- you can be assured that every element in // the list of ingredients will be one of the ingredients mentioned above.
/* Check out README.md for instructions! */ function isProperBurger(burger) { /* 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")(isProperBurger) /* Test cases (remember to add more!) */ // no ingredients, no burger! expect(false, []) // a proper cheese burger expect(true, ["bread", "patty", "cheese", "bread"]) // your test case here! // expect(expectedProper, burger)
/* 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` ) } }
Editor Settings
Theme
Key bindings
Full width
Lines