suggestion: for group by
Aberta
enhancement
- Linguagem predominante
- JavaScript
- Estrelas
- 6.2k
- Forks
- 210
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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
}
```
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.