Maulik
Maulik

Reputation: 795

perform groupBy from underscore.js without applying sort order

I've applied groupBy to collection and it applies default sorting on column which is used for groupBy operation

_.groupBy(result, "ColumnName")

I don't want to apply sorting to my collection, want to preserve order of collection, but i dont see any proper documentation from underscore.js for groupBy method without sorting.

Upvotes: 0

Views: 124

Answers (1)

Maulik
Maulik

Reputation: 795

The problem with _.groupBy from Underscore.js is when we perform on numeric property of collection it does apply ascending sorting automatically, and for string property it does preserves the sequence of collection.

So if someone is using _.groupBy on numeric property then need to apply sorting again on grouped collection if want to apply specific sort order on collection.

I believe there is not other way to avoid sorting while performing groupBy with underscore.js library on numeric property, It's a limitation.

Upvotes: 1

Related Questions