-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevery.js
52 lines (37 loc) · 915 Bytes
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*jshint esversion: 6 */
// Every //
// Runs the && operator on returned values,
// and returns either true or false
// true && true && false == false
// true && true && true == true
var computers = [
{ name: "Apple", ram: 24 },
{ name: "Compaq", ram: 4 },
{ name: "Acer", ram: 32 },
];
var canTheyRunIt = computers.every(function(computer) {
return computer.ram > 16;
});
console.log(canTheyRunIt);
var names = [
"Alex",
"Joe",
"Matthew",
];
var allNamesGreater = names.every(function(name) {
return name.length > 4;
});
console.log(allNamesGreater);
function Field(value) {
this.value = value;
}
Field.prototype.validate = function() {
return this.value.length > 0;
};
var username = new Field("cool");
var password = new Field("");
var fields = [username, password];
var formIsValid = fields.every(function(field) {
return field.validate();
});
console.log(formIsValid);