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 you pass just an arr to a function (for Math.min and .max in this case) it will consider it as an argument and return not a number, but if you add a spread operator, it will consider each element of arr as an individual argument. It is same if you pass all array elements to the function manually(eg. Math.min(1,2,3,4,5)).
Yes, but my point was that this isn't best practice.. just clever.
the description says the input will be all positive integers
It was good practice.
Good, but if they were to pass negative numbers as an input and it would fail..
Ah, nice. I didn't know if this would work or not so I just assigned the min and max to variables and returned them in an array. Very clean.
I think you do not need to worry about that cuz nowadays devices are pretty powerful to worry about difference in milliseconds)
Three dots like that is "spread syntax", basically it allows an iterable (like an array in this case) to be expanded into multiple arguments in certain situations.
Read more about it on mdn here, I think the example given is a good demonstration:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
what does ... do? I searched it and can't understand.
Lol nice, mine was a one liner but i first checked if there's one element, then if not sorted, sliced first and last element and concated it
Destructuring at its finest
Desturcturing at its finest!
Best
Same, the best way remember is to keep practice & repeating. Happy coding!
Looping once isn't definitely going to be better in terms of time than looping twice. You are still going to compare for both min and max in your loop, not to mention the overhead of min/max variables and conditional statements.
Loading more items...