Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
If the recipe is blank it is logically perfectly correct to return Infinity (or whatever, in fact).
We can add this at the first line: if (Object.keys(recipe).length === 0) return 0;
It will save us from empty recipe.
In the rest this solution seems to be the best practice.
+1
I was thinking the same thing, I had never thought of using this syntax in functions arguments, useful
This comment is hidden because it contains spoiler information about the solution
Basically, this one has it all and I've never said that before. It's waaay better than mine. The only thing: if line 2 was "var result = [];" you wouldn't need the ternary on line 5, you'd just concat every time.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Yours has MORE RegExp and is LESS readable, what are you talking about. And if the scoring was going to be changed, you'd have to change your patterns in two places instead of one.
Is it just me or is this written to loop though every single node of the array before recognizing duplicates? You should be able to break much earlier than that if you've touched a duplicate inside a loop. And if you sort and join, doesn't that loop through an array as well?
If the recipe is blank, you return Infinity. You don't provide for breaking the loop as soon as you know you can produce 0 of the recipe. There are two cases where that can happen.
I don't think "if (key in supplies)" is really what you want to go for here. If supplies.key == 0 it makes you do that math, push zero to your array, and continue the array instead of just returning 0. And why an array of numbers? You just need the smallest number you've found yet and return it at the end.
I have to credit this solution for one thing, using an operator I hadn't seen before. I just learned a lot of new operators.
The loop's first if is unnecessary. You don't need an array, you just need a single integer, maximum cakes, that decreases to the smallest integer on each loop. If your Math.floor results in a zero, you need to return 0 then and there.
Loading more items...