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.
Start your free trialhakan Gülay
8,489 PointsI couldnt understand how it orders
http://teamtreehouse.com/library/javascript-foundations/arrays/methods-part-2
Hi,in this video my_array.sort(function(a,b){ return a-b; }); that code, ı really couldnt understand how it orders from small to large. can you please explain to me ?
3 Answers
Chris Shaw
26,676 PointsHi Hakan,
MDN have a great explanation for that exact example.
Ken Alger W3 Schools is considered to be a bad reference as it's not updated and lacks newer information about today's standards, you can read more about this over at http://www.w3fools.com/.
hakan Gülay
8,489 PointsThank you a lot guys I got it now really :)
David Rynn
10,554 PointsThanks for this guys. I didn't understand that the sort method is set up to take either a negative or positive value from a supplied compare function. Otherwise it reverts to it's default (sorting by string). So the coder needs to create a function that compares two numbers and which ever one is negative goes first.
Iago Wandalsen Prates
21,699 PointsIago Wandalsen Prates
21,699 PointsW3 was really bad at some point, but nowadays its pretty decent. When w3fools launched years ago, they had extensive data about fucked up things on W3, now they just say its not the best.
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsI personally haven't used their site in years, for at least the past 4 years I've referred to the Mozilla Developer Network.
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsI think you're mistaking W3Schools which have no affiliation to the W3C or World Wide Web Consortium as they're known.
Also I find it somewhat unusual that you say you prefer less information as generally the more you have the easier it is to understand.
In any case I believe Hakan has plenty of information now :)
Iago Wandalsen Prates
21,699 PointsIago Wandalsen Prates
21,699 PointsI'm not mistaking, I'm talking about w3Schools. Nowadays most of their content is pretty ok, and its easier to understand in case you dont know much about documentation, besides the fact it uses a generally more simple vocabulary, even tough its not always 100% correct. ex on documentation is things like function (arg1, [context]) if you are not experienced, you dont really understand whats the brackets doing there
James Barnett
39,199 PointsJames Barnett
39,199 PointsIf you are looking for HTML & CSS references there are better choices than W3Schools. Also many newbies here on the forum aren't clear about the distinction between the W3C and W3Schools, so anytime you post a link to it it's best to clarify the lack of affiliation.
In terms of vanilla JavaScript there is no really great source I've found online.