Created
April 3, 2018 17:44
-
-
Save mrboli/f113821b25ed03c5ec483049edd1618e to your computer and use it in GitHub Desktop.
[incomplete][idea] Code Wars - Chained - https://www.codewars.com/kata/54c27ef1fb7da0118600046a/train/javascript
This file contains hidden or 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
| function chain(fns) { | |
| let c = {}; | |
| let toEx = []; | |
| for (let fn in fns) { | |
| this[fn] = fns[fn]; | |
| c.[fn] = function () { | |
| toEx.push({ [fn]: arguments }); | |
| } | |
| } | |
| return { | |
| // sum, other functions | |
| execute: function () { | |
| } | |
| } | |
| } |
This file contains hidden or 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
| function sum(x, y) { | |
| return x + y; | |
| } | |
| function double(x) { | |
| return sum(x, x); | |
| } | |
| function minus (x, y) { | |
| return x - y; | |
| } | |
| function addOne(x) { | |
| return sum(x, 1); | |
| } | |
| let c = chain({sum, double, minus, addOne}); | |
| console.log(c.sum); | |
| c.sum(a, b) // { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment