📅  最后修改于: 2022-03-11 15:03:09.493000             🧑  作者: Mango
function groupBy(array, callback) {
return array.reduce((acc,cur) => {
let key = callback(cur)
acc[key] = acc[key] || [];
acc[key].push(cur)
return acc;
},{})
}
const decimals = [1.3, 2.1, 2.4];
const floored = function(num) {
return Math.floor(num);
};
console.log(groupBy(decimals, floored));