-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevery.js
38 lines (32 loc) · 1.38 KB
/
every.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
// TOPIC /////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Array Method: .every()
//
// SYNTAX ////////////////////////////////////////////////////////////////////////////////////////////////////
//
// array.every(function(currentValue, index, arr), thisValue)
//
// SUMMARY ///////////////////////////////////////////////////////////////////////////////////////////////////
//
// • .every() method checks to see is all element in an array pass a test (provided as a function)
//
// EXAMPLES //////////////////////////////////////////////////////////////////////////////////////////////////
//
// EXAMPLE 1: Determine if every number in an array is positive:
//
// RESOURCES /////////////////////////////////////////////////////////////////////////////////////////////////
//
// https://medium.com/@JeffLombardJr/when-and-why-to-use-the-every-array-method-in-javascript-29ff42a40522
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EXAMPLE 1: Determine if every number in an array is positive:
let array1 = [1,2,3,4,5];
let array2 = [6,7,8,9,10];
let array3 = [-1,0,1,2,3];
function isPositive(number) {
return number > 0;
}
console.log(array1.every(isPositive));
console.log(array2.every(isPositive));
console.log(array3.every(isPositive));