-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculatingWithFunction.js
72 lines (68 loc) · 1.48 KB
/
calculatingWithFunction.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
72
// https://www.codewars.com/kata/525f3eda17c7cd9f9e000b39
// This time we want to write calculations using functions and get the results. Let's have a look at some examples:
// Examples
// seven(times(five())); // must return 35
// four(plus(nine())); // must return 13
// eight(minus(three())); // must return 5
// six(dividedBy(two())); // must return 3
function executeValue(callback) { return typeof callback === 'function' ? callback(value) : value }
function zero(callback) {
const value = 0;
return executeValue(callback);
}
function one(callback) {
const value = 1;
return executeValue(callback);
}
function two(callback) {
const value = 2;
return executeValue(callback);
}
function three(callback) {
const value = 3;
return executeValue(callback);
}
function four(callback) {
const value = 4;
return executeValue(callback);
}
function five(callback) {
const value = 5;
return executeValue(callback);
}
function six(callback) {
const value = 6;
return executeValue(callback);
}
function seven(callback) {
const value = 7;
return executeValue(callback);
}
function eight(callback) {
const value = 8;
return executeValue(callback);
}
function nine(callback) {
const value = 9;
return executeValue(callback);
}
function plus(a) {
return (b) => {
return a + b
}
}
function minus(a) {
return (b) => {
return b - a
}
}
function times(a) {
return (b) => {
return a * b
}
}
function dividedBy(a) {
return (b) => {
return Math.floor(b/a)
}
}