-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
small-enough-beginner.js
71 lines (60 loc) · 1.44 KB
/
small-enough-beginner.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function smallEnough(a, limit){
// iterate over the array
// if the current value is greater than the limit
// return false
// return true
}
function smallEnough(a, limit){
for (let i = 0; i < a.length; i += 1) {
if (a[i] > limit) {
return false;
}
}
return true;
}
function smallEnough(a, limit){
let allUnderLimit = true;
a.forEach((number) => {
if (number > limit) {
allUnderLimit = false;
}
});
return allUnderLimit;
}
function smallEnough(a, limit){
return a.reduce((allUnderLimit, number) => {
if (number > limit) {
return false;
}
return allUnderLimit;
}, true);
}
function smallEnough(a, limit){
return a.filter((number) => {
return number > limit
}).length === 0;
}
function smallEnough(a, limit){
let i = 0;
while (a[i] <= limit) {
i++;
}
if (i === a.length) {
return true;
}
return false;
}
function smallEnough(a, limit){
return a.every((number) => number <= limit);
}
function smallEnough(a, limit){
return !a.some((number) => number > limit);
}
Array.prototype.any = Array.prototype.some;
function smallEnough(a, limit){
return !a.any((number) => number > limit);
}
console.log(smallEnough([66, 101], 200), true);
console.log(smallEnough([78, 117, 110, 99, 104, 117, 107, 115], 100), false);
console.log(smallEnough([101, 45, 75, 105, 99, 107], 107), true);
console.log(smallEnough([80, 117, 115, 104, 45, 85, 112, 115], 120), true);