everyIsPositive

Easy · Functional Programming Concepts · 3 test cases

Given an array of numbers, use the `every` method to check if all numbers in the array are positive.

Examples

everyIsPositive([1, 2, 3]) → true
everyIsPositive([1, -2, 3]) → false

Starter code

function everyIsPositive(arr) {

}

Complexity of the optimal solution

Time O(n), space O(1). The `every` method iterates through the array, but stops as soon as it finds an element that does not satisfy the condition. In the worst case (all elements are positive), it checks all 'n' elements. Space is constant.

Solve everyIsPositive in the browser