0

When we sort an array we write our function like the following, what does the last_nom mean here?

objs.sort(function(a, b){
return a.last_nom == b.last_nom ? 0 : +(a.last_nom > b.last_nom) || -1;
});

Trying to understand the concept behind but failed to find useful explanation. Thanks for your help in advance!

Bray
  • 361
  • 1
  • 10
  • Belongs on: http://codereview.stackexchange.com/ – Diodeus - James MacFarlane Aug 12 '14 at 17:48
  • 1
    last_mon is probably a key (from a key/pair object). Something like: a = { last_nom: "benseler", first_nom: "christian" }. Take a lok at: http://stackoverflow.com/questions/1129216/sorting-objects-in-an-array-by-a-field-value-in-javascript – Christian Benseler Aug 12 '14 at 17:49
  • 2
    It's for [sorting an `Array` of `Object`s](http://stackoverflow.com/questions/1129216/sorting-objects-in-an-array-by-a-field-value-in-javascript). `last_nom` would be a property of each object. – Jonathan Lonowski Aug 12 '14 at 17:50
  • what is the last_num properties though? do the array/objects have this property when they are created? – Bray Aug 12 '14 at 17:53
  • @BRAYBRAY Yes. The objects in the array should already have a `last_nom` property for this `.sort()` to use them. An example is given in the text of the question I linked. – Jonathan Lonowski Aug 12 '14 at 17:54

1 Answers1

1

The code expects a and b to have a property called last_nom

celeritas
  • 2,191
  • 1
  • 17
  • 28