Explorer
Node.js

Write a function `checkArray(arr)` that returns `{ hasNegative, allPositive }` — whether any element is negative and whether all are positive.

Problem Statement

Write a function `checkArray(arr)` that returns `{ hasNegative, allPositive }` — whether any element is negative and whether all are positive.

Complexity

Time Complexity: -

Space Complexity: -

Hints

💡 Hint 1: Array.some() returns true if at least one element passes the test. 💡 Hint 2: Array.every() returns true only if all elements pass the test. 💡 Hint 3: hasNegative: arr.some(n => n < 0), allPositive: arr.every(n => n > 0). ✅ Solution: ```javascript function checkArray(arr) { return { hasNegative: arr.some(n => n < 0), allPositive: arr.every(n => n > 0) }; } ```

Array.some and Array.every

Easy
Write a function `checkArray(arr)` that returns `{ hasNegative, allPositive }` — whether any element is negative and whether all are positive.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
[{"hasNegative":false,"allPositive":true},{"hasNegative":true,"allPositive":false},{"hasNegative":true,"allPositive":false}]