var add = function(x) {
return function(y) {
return x + y;
}
}
var increment = add(1);
console.log(increment(2));
var addTen = add(10);
console.log(addTen(5));
var curry = _.curry;
/*
_.curry(func, [arity=func.length])
创建一个函数,该函数接受一个或多个func的参数。当该函数被调用时,如果func所需要的所有参数被提供,则直接返回func所执行的结果。否则继续返回该函数并等待接受剩余的参数。可以传入func.length强调所需要累计的参数个数
*/
// console.log(curry)
var match = curry(function (what, str) {
return str.match(what);
})
var replace = curry(function(what, replacement, str) {
return str.replace(what, replacement);
})
var filter = curry(function(f, ary) {
return ary.filter(f)
})
var map = curry(function (f, ary) {
return ary.map(f)
})
var hasSpaces = match(/\s+/g);
// hasSpaces = function(str) {
// return str.match(/\s+/g)
// }
var findSpaces = filter(hasSpaces);
// findSpaces = function(ary) {
// return ary.filter(function(str) {
// return str.match(/\s+/g);
// })
// }
var noVowels = replace(/[aeiou]/ig);
// noVowels = function(replacement, x) {
// return x.replace(/[aeiou]/ig, replacement)
// }
var censored = noVowels('*');
// censored = function(str) {
// return str.replace(/[aeiuo]/ig, '*')
// }
var a = match(/\s+/g, "helloworld");
var a1 = hasSpaces("hello world");
console.log(a1);
var a2 = findSpaces(['abc_123', 'go go']);
console.log(a2);
var a3 = censored('chocolate rain');
console.log(a3);
console