Skip to content

Instantly share code, notes, and snippets.

@XiongLiding
Created June 16, 2020 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XiongLiding/0c6da3b3b8cb9cc3ef7e4bdb3325d746 to your computer and use it in GitHub Desktop.
Save XiongLiding/0c6da3b3b8cb9cc3ef7e4bdb3325d746 to your computer and use it in GitHub Desktop.
通过递归实现任意级别的分组功能,第一个参数是作为分组依据的函数的数组,第二个参数是初始的数据数组
const { map, groupBy } = require("rambda");
const nestGroupBy = ([fn, ...fns], list) => {
if (!fn) {
return list;
}
const g = groupBy(fn, list);
return map(v => {
return nestGroupBy(fns, v);
}, g);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment