## Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

### Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

PLUS

# Sort Numerically in Arrays

I've watched the video and passed the code challenge but I'm really interested in why

```javascript

x.sort(function(a,b) {
return a-b;

});
```

functions as it does to return the appropriate result. It seems the "SortFunction" is only concerned with positivity, negativity, or equality in the return. Many examples online create code which returns 0, -1, or 1 as a result of the comparison between a and b. For the purposes of SortFunction 0,-8,3 are equivalent to 0,-1,1.

However, I don't understand how it is that a and b are actually called. It seems like it could become computationally expensive for the function to call every possible set of numbers and compare them individually and return the result.

I suppose that makes it a testable hypothesis because there should be an increase in time-to-return as the set increases in size. If this is the case and each possible pairing is truly compared then what implications does this have for using the SortFunction numerically in our code when producing web applications? Is it only practical/functional on small sets of information? Would an array large enough to slow this function be terrible practice anyway and therefore practically result in the law that any array too big to sort is an array too big to use?