0

I have a function that sorts objects. I want to use collator.compare and I am not sure how to put it inside the function or the way to use it. Here is the custom sorting function.

  compare: function(a,b) {
    if (a.name < b.name)
      return -1;
    if (a.name > b.name)
      return 1;
    return 0;
  },

I want to sort using collator

var objs = [{name: '1_Document', size: 40}, {name: '11_Document', size: 50}, {name: '2_Document', size: 60}];

var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
objs.sort(compare)

And my goal is to use collator.compare inside the function, how can I achieve that?

user2004082
  • 141
  • 2
  • 8

0 Answers0