DEV Community

Discussion on: 6 JavaScript WTFs and what to learn from them

Collapse
 
eusebiu profile image
Eusebiu Marcu

"Imagine that you will have to implement a function that find the maximum value from an array. That's easy! The simplest way to do it is to iterate through the entire array, compare the elements and store the maximum value. Here's the twist! That variable where you store the maximum value should be initialized with a very, very small value, the smallest." - no, you initialize the maximum with the first element (ofc, if it exists).

Collapse
 
andreib123 profile image
Andrei Bumbu

Yes, you are right.

In this phrase I tried to describe the approach used in some classes with beginners (in high school for example) where the focus is that the student understands the big picture.
The "simplest way to do it" part should get you thinking about that, but maybe I should have been more clearer that is not a best practice.

Thanks for the intervention!