View Single Post
  #2 (permalink)  
Old February 15th, 2016, 09:01 PM
MrAnalogy MrAnalogy is offline
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default .sort accepts a Function() as a parameter

See specs on array.sort()

That sort function should have two object parameters (a,b below) which (I assume) just get "magically"* passed to that function by the .sort function.


As touched on already, array.sort() accepts an optional parameter in the form of a function reference (lets call it sortfunction). The format of this function looks like this:
array.sort(sortfunction)

function sortfunction(a, b){
//Compare "a" and "b" in some fashion, and return -1, 0, or 1
}


* I'm new to .js And:
Any sufficiently advanced technology is indistinguishable from magic.
Reply With Quote