Created
May 17, 2019 12:13
-
-
Save pixelkritzel/aaf0234e153aab0d7f24211dec78db26 to your computer and use it in GitHub Desktop.
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 ready(payload) { | |
const fns = [] | |
let lastReturnValue = payload; | |
function steady(fn) { | |
fns.push(fn) | |
return { | |
steady, go | |
} | |
} | |
function go() { | |
fns.forEach(fn =>(lastReturnValue = fn(lastReturnValue))) | |
return lastReturnValue | |
} | |
return { | |
steady | |
} | |
} | |
console.log( | |
ready('Hello, I am ready steady go') | |
.steady(text => Array.from(text)) | |
.steady(arr => arr.reverse()) | |
.steady(arr => arr.map(c => c.toUpperCase())) | |
.steady(arr => arr.join(' ')) | |
.go() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment