proposal-array-grouping icon indicating copy to clipboard operation
proposal-array-grouping copied to clipboard

Other lodash use cases where the method could be handy

Open viktor-yakubiv opened this issue 4 years ago • 0 comments

Thanks for creating this function proposal, I am very exiting to see it. I find this could be useful for many use cases, here are some of them from lodash.

Chunk

const chunk = (array, size = 1) => Object.values(array.groupBy((v, i) => Math.floor(i / size)))

Partition

// predicate returns boolean
const partition = (array, predicate) => Object.values(array.groupBy((v, i, a) => Number(predicate(v, i, a)))

Covered by proposal in #9


Covering Object.values() order consistency was left out for the simplicity.

If this is not worth adding to examples, feel free to close the issue. Thank you 🙂

viktor-yakubiv avatar Oct 27 '21 13:10 viktor-yakubiv