Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

group by

function groupBy(array, keyFn) {
  return array.reduce((accumulator, value) => {
    const key = keyFn(value);
    if (!accumulator[key]) {
      accumulator[key] = [value];
    } else {
      accumulator[key] = [value];
    }
    return accumulator;
  }, {});
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #group
ADD COMMENT
Topic
Name
8+5 =