Count Negative
JavaScript
easy
10 mins
Given an array arr of numbers, return the count of elements strictly less than 0.
Examples
Input: arr = [-1, 0, 1] Output: 1
Input: arr = [-2, -5, -7] Output: 3
Input: arr = [0, 2, 3] Output: 0
Input: arr = [] Output: 0
Input: arr = [] Output: 0 countNegatives([-1, 0, 1]) // 1 countNegatives([-2, -5, -7]) // 3 countNegatives([0, 2, 3]) // 0 countNegatives([]) // 0
Constraints
- If input is not an array, return false.
- If the array contains any non-number values or non-finite numbers (NaN, Infinity, -Infinity), return false.
- An empty array is valid and should return 0.
Companies:
Accenture
amazon
tcs
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
