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)
};
}
```