The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Lodash - sortBy and sortedIndex

Lodash - sortBy and sortedIndex

3:38
Lodash's "sortBy" method helps you sort data in your collections and "sortedIndex" helps you find where to place new data. In this video, John walks you through how to use each of these methods and how they can work together.
Watch this lesson now
Avatar
egghead.io

Lodash's "sortBy" method helps you sort data in your collections and "sortedIndex" helps you find where to place new data. In this video, John walks you through how to use each of these methods and how they can work together.

Avatar
Alasdair

I'm presuming using sortedIndex and spliced is more efficient than pushing newGuy onto the end and then resorting - just how much of a difference does this make?

In particular how quick is the insert by sortedIndex stage?

Avatar
John

He keeps a suite of benchmarks here:
https://lodash.com/benchmarks

Looks like they're down for the moment.

As for "index then splice" vs. "push then sort", I'm pretty sure the answer is "it depends" on your data.

In reply to Alasdair
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?