2

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!

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

How large are the value types in memory?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.