Facebook Pixel

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 🔥

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.