angus-c / angus-c/just

suggestion: for group by

Aperta
#494 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
JavaScript
Stelle
6.2k
Fork
209
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

1. make it acceptable of iterable objects
2. use `Object.create(null)` to avoid having to check if xyz is an array using Array.isArray
3. allow using a 3th argument as a destination object that defaults to an object. (incase you need to use the same object for more stuff)
4. use `??=` assignment to clamp it down even more

```js
function groupBy(iterable, cb, dest = Object.create(null)) {
if (typeof cb !== 'function') throw new Error('expected a function for second argument')
if (typeof dest !== 'object') throw new Error('expected a object for third argument')

for (var item of iterable) (dest[cb(item)] ??= []).push(item)

return dest
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.