Javascript learning: Sorting

Sorting of arrays in javascript is so cool and simple! Below you see some code which is used to sort the example array.

Sorting code

Each item in myData has three properties:

{name:xx, type:xx, rank:##}

Which one you compare will decide how your array is sorted.

myData.sort(function(a,b) {
   return
})

You should return either -1 (set a first), 0 (unchanged) or 1 (set b first) .

Sorted array