Skip to content

Instantly share code, notes, and snippets.

@kreja
Last active March 29, 2016 03:40
Show Gist options
  • Save kreja/e618f71b3bd2e281cc8a to your computer and use it in GitHub Desktop.
Save kreja/e618f71b3bd2e281cc8a to your computer and use it in GitHub Desktop.
mostly-adequate-guide
// https://github.com/MostlyAdequate/mostly-adequate-guide
// https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/ch5.html
// this is my practice while reading the book
var compose = function(){
var args = arguments;
return function(x){
var res = x;
for(var i=args.length-1; i>=0; i--){
res = args[i](res);
}
return res;
};
};
var toUpperCase = function(str){
return str.toUpperCase();
};
var getMatchFn = function(RegExp){ // it's a curry func!
return function(str){
var res = str.match(RegExp);
return res && res[0] || 'not matched';
};
};
var findHello = function(s){
return getMatchFn(/hello/)(s);
};
var strengthHello = compose(toUpperCase, findHello);
console.log( strengthHello('yo hello world') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment