API Reference

Runs a callback function on array of items and returns a single object with keys that match the return values. Each key's value is an array of items that provide the same result when having the callback function run on them.

function groupBy(things: any[], func: Function)

// Example:

const people = [
                 { name: "John", age: 28 }, 
                 { name: "Brittany", age: 14 }, 
                 { name: "Susan", age: 67 }, 
                 { name: "Jeff", age: 17 }
               ]
 
const canDrinkAlcohol = (person: { age: number }) => person.age >= 21
 
groupByCallbackResult(people, canDrinkAlcohol)
 //=>
      {
       "true": [
         { name: "John", age: 28 },
         { name; "Susan", age: 67 }
       ]
       "false": [
         { name: "Brittany", age: 14 },
         { name: "Jeff", age: 17 }
       ]
      }