Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript sorted lists

Is there a sorted list in Javascript or jQuery?

I have a huge list with few insert actions over time. I cannot afford to call object.sort() for the entire list each time I add a single item. I need an insert of o(log(n));

like image 394
eshalev Avatar asked Mar 07 '11 10:03

eshalev


1 Answers

No, there isn't, all you have is Array#sort which you've ruled out using repeatedly (and with good reason!). You'll have to use an insertion sort approach.

like image 123
T.J. Crowder Avatar answered Oct 13 '22 22:10

T.J. Crowder