I think this was designed for the more common usecase of search algorithms looking for new minimum or maximum values.
You will always be greater than the max of an empty list, and always less than the min of an empty list, without needing to check for the edgecase of an empty list.
seen_values = [];
[1,-2,3,-5,4].foreach((value) => {
if( value > Math.max(seen_values) ) {
onNewMaxValue(value);
}
if( value < Math.min(seen_values) ) {
onNewMinValue(value);
}
seen_values.push( value )
})
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think this was designed for the more common usecase of search algorithms looking for new minimum or maximum values.
You will always be greater than the max of an empty list, and always less than the min of an empty list, without needing to check for the edgecase of an empty list.