I created an array of integers and wanted to know if it had one or more negative values in it.
I do not want to create a for() loop and check if each element in the array is positive or negative because I only want to return once (ex: I don't want my function to "return false;" a million times).
One option I considered was multiplying each value in the array by the absolute value of its reciprocal, so I get an array of 1s or -1s (or undefined if value is 0) and then I could sum all of the values in this second array to see if it equals the length of the array.
However, the problem with this method is it does not account for 1/0, and also it is tedious. I want to know if there is a faster way to check if an array contains at least one negative value.
--from a beginner JavaScript programmer
Array#some
-const hasNegative = arr.some( x => x < 0 );