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.
This comment is hidden because it contains spoiler information about the solution
Or just use the spread operator
Math.min(... numbers)
instead.(Ref. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator)
The solution is still invalid because it mutates the original array. The final kata test should have had a guard against that...
Nope that's not the goal. The problem with looking at other people's solutions is that they might be further down the line in expertise. Like Dahlia said, it will become more natural with time.
My coding instructor taught us to try to achieve succinct code in this manner, in sequential order:
And ultimately, don't strive to cram everything in one line. I think that's just being silly. Yes it's cool, but a lot of times I'll find a one-liner to be not as human readable as a 3-5 liner. The goal is to strike a good balance between readability and efficiency. (And more lines of code doesn't necessarily mean less efficient code - a nested
for
loop takes only 5 lines in JavaScript but can be really inefficient.)This comment is hidden because it contains spoiler information about the solution
In case anyone is wondering (like I was) how Math.min.apply(null, numbers) works, have a read at MDN's documentation for apply() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply