The value associated with each key will be an array consisting of all the elements that resulted in that return value when passed into the callback.

JavaScript
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));
Source

Also in JavaScript: