-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathcallApplyBind.js
More file actions
46 lines (43 loc) · 1000 Bytes
/
callApplyBind.js
File metadata and controls
46 lines (43 loc) · 1000 Bytes
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
function sumEvenArguments() {
var arr = [].slice.call(arguments);
var sum = 0;
for(var i = 0; i <= arr.length; i++) {
if (arr[i] % 2 === 0) {
sum += arr[i];
}
}
return sum;
}
function arrayFrom() {
var arr = [].slice.call(arguments);
return arr;
}
function invokeMax(fn, max) {
var counter = 0;
return function() {
var innerArgs = [].slice.call(arguments);
if (counter >= max) {
return "Maxed Out!";
} else {
counter++;
return fn.apply(this, arguments);
}
}
}
///yeah still need clarification on how this works ^
function guessingGame(amount) {
var answer = Math.floor(Math.random() * 10);
var guesses = 0;
return function(guess) {
guesses++;
if (guesses > amount) {
return "You are all done playing!";
} else if (answer < guess) {
return "You're too high!";
} else if (answer > guess) {
return "You're too low!";
} else if (answer === guess) {
return "You got it!";
}
}
}