
好处说明
1、可以把函数式编程变得简洁,没有冗余。
2、尽管有多个参数,仍然可以保留数学函数的定义。
3、可以将函数作为返回值输出,提前返回。
实例
match(/r/g,'helloworld');//['r']
consthasLetterR=match(/r/g);//x=>x.match(/r/g)
hasLetterR('helloworld');//['r']
hasLetterR('justjandsandtetc');//null
filter(hasLetterR,['rockandroll','smoothjazz']);//['rockandroll']
constremoveStringsWithoutRs=filter(hasLetterR);//xs=>xs.filter(x=>x.match(/r/g))
removeStringsWithoutRs(['rockandroll','smoothjazz','drumcircle']);//['rockandroll','drumcircle']
constnoVowels=replace(/[aeiou]/ig);//(r,x)=>x.replace(/[aeiou]/ig,r)
constcensored=noVowels('*');//x=>x.replace(/[aeiou]/ig,'*')
censored('ChocolateRain');//'Ch*c*l*t*R**n'
以上就是js柯里化函数的好处,希望对大家有所帮助。更多js学习指路:js教程
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容