-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michal
authored and
Michal
committed
Jul 12, 2020
1 parent
203e61a
commit 869e526
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} |