So, I have an array of 100,000+ items, and this line causes it to blow the call stack:
@sortedList.sort (a, b) ->
return if a.value > b.value then -1 else 1
I’m about to go implement a custom sort of some variety (suggestions, anyone?) to work around the issue, but I just wanted to make sure that I’m not doing something blatantly stupid that’s causing it to blow up.
What happens if
a.value == b.value? Asortcomparison function should return zero if the items are the same:So you want something more like this:
The missing
a.value == b.valuebranch could causesortto lose its mind and make a mess all over the place; no==branch is saying thatagoes beforebandbgoes beforea, you can’t expect a sensible result from that.