Skip to content

Instantly share code, notes, and snippets.

@ruanyf
Last active March 11, 2017 15:24
Show Gist options
  • Save ruanyf/47e5d4f06194e9745e64f4c0404e3f78 to your computer and use it in GitHub Desktop.
Save ruanyf/47e5d4f06194e9745e64f4c0404e3f78 to your computer and use it in GitHub Desktop.
Pointfree Demo One
var str = 'Lorem ipsum dolor sit amet consectetur adipiscing elit';
// 以空格分割单词
var splitBySpace = s => s.split(' ');
// 每个单词的长度
var getLength = w => w.length;
// 词的数组转换成长度的数组
var getLengthArr = arr => R.map(getLength, arr);
// 返回较大的数字
var getBiggerNumber = (a, b) => a > b ? a : b;
// 返回最大的一个数字
var findBiggestNumber = arr => R.reduce(getBiggerNumber, 0, arr);
// 合成运算
var getLongestWordLength = R.pipe(
splitBySpace,
getLengthArr,
findBiggestNumber,
);
getLongestWordLength(str) // 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment