implementation.js 660 B

1234567891011121314151617181920
  1. 'use strict';
  2. var CreateDataPropertyOrThrow = require('es-abstract/2022/CreateDataPropertyOrThrow');
  3. var OrdinaryObjectCreate = require('es-abstract/2022/OrdinaryObjectCreate');
  4. var forEach = require('es-abstract/helpers/forEach');
  5. var GroupBy = require('./aos/GroupBy'); // TODO: replace with es-abstract 2024 implementation
  6. module.exports = function groupBy(items, callbackfn) {
  7. var groups = GroupBy(items, callbackfn, 'property'); // step 1
  8. var obj = OrdinaryObjectCreate(null); // step 2
  9. forEach(groups, function (g) { // step 3
  10. CreateDataPropertyOrThrow(obj, g['[[Key]]'], g['[[Elements]]']); // steps 3.a - 3.b
  11. });
  12. return obj; // step 4
  13. };