Lodash - sortBy and sortedIndex

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

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.

Alasdair
~ 9 years ago

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?

John Lindquistinstructor
~ 9 years ago

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.