Count number of negative values in array
How to solve it
I recommend solving this challenge in a 2-step process.
First, we will filter the existing array and only keep negative values. This is done using the array.filter method that we introduced in this challenge.
Remember that this method is used to exclude elements from an array based on a certain condition. For example, we can remove all elements from an array of strings that do not contain the letter e:
const strings = ['ear', 'eco', 'sad', 'say'];console.log(strings.filter(str => str.includes('e')));// output: ['ear', 'eco']
For the present challenge, the condition of the filter would be: element has to be a negative number.
Then, we will count the number of elements in the remaining array using the array.length method that we introduced in this challenge.