How about checking array is valid (as an numeric array which length > 0) via:
if (!Array.isArray(array) || !array.length || array.some(isNaN)) {
return ("Not a valid array")
}
Regarding the 0 comparison, how about:
let max = -Infinity, second = -Infinity
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.
How about checking array is valid (as an numeric array which length > 0) via:
if (!Array.isArray(array) || !array.length || array.some(isNaN)) {
return ("Not a valid array")
}
Regarding the 0 comparison, how about:
let max = -Infinity, second = -Infinity