views:

132

answers:

1

Hey out there in Stackland.

I'm making a very javascript-heavy site, and at a certain point I have to take a whole bunch of objects in an array and then sort them by their distance from a certain point. I don't know the nature of objects in JS, and was wondering if this array sort would take longer with larger objects, or if it is the equivalent of changing pointers to different objects, which would mean that the size of the objects would be trivial. Any help would be great!

Thanks!

+6  A: 

Values in JavaScript are either value types (booleans, null, numbers, strings) or reference types (objects, functions). There aren't any values that would be effectively large (strings are pointers behind the scenes) so your array sort speed should be only dependent on the number of items, not the size of them. Also, the base Array.sort() is faster than the one that takes a function, but you're kind of stuck with the latter.

Anthony Mills
thank you Anthony!
Ethan