Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 615 Bytes

.verb.md

File metadata and controls

38 lines (33 loc) · 615 Bytes

Usage

var sortBy = require('{%= name %}');
sortBy(array, {
  prop: 'foo', // the property name to sort by
  values: ['a', 'b', 'c'] // the property values to sort by
});

Example

var arr = [
  {title: 'Foo'},
  {title: 'Baz'},
  {title: 'Bar'},
  {title: 'Qux'},
  {title: 'Faz'},
  {title: 'Fez'}
];

var res = sortBy(arr, {
  prop: 'title',
  values: ['Faz', 'Qux', 'Bar'],
  normalize: function(val) {
    return val;
  }
});

console.log(res);
// [ { title: 'Faz' },
//   { title: 'Qux' },
//   { title: 'Bar' },
//   { title: 'Foo' },
//   { title: 'Baz' },
//   { title: 'Fez' } ]