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.
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.
I believe the time complexity is still linear for both examples. The Math.max/min solution does have two loops but they are not nested. It would end up being O(2n) which would still condense down to O(n) like your solution. I think ultimately the one liner is more readable which would make it preferable. Please correct me if I'm missing something
This is an easy and readable code. Here there is no mention of writing the best code considering the Big O of the code running. So this can be a better option to do.
technically you have the more complex solution
false
,0
,""
,null
andundefined
all have the property that when used in a if statement that they will equate tofalse
. So it isn't necessary at all.As for production code, it is used without the
=== true
. Which is generally done for all if statements. We also don't write code like