Closed bennlich closed 3 years ago
Whoa, just thought a bit about it. Having min start at 0 is likely a problem, right? Maybe min should start at +Infinity and max at -Infinity. ... and with a warning.
I just switched to this:
min(key) {
return this.reduce(
(prev, o) => Math.min(prev, key ? o[key] : o),
Infinity
)
}
max(key) {
return this.reduce(
(prev, o) => Math.max(prev, key ? o[key] : o),
-Infinity
)
}
What do you think?
Nice! Good catch.
Makes sense, empty arrays return 0. But maybe better would be to check for empty and either throw an error or return null or nan +/- infinity.
But throwing is likely silly and 0 seems reasonable