File: custom-function.js

package info (click to toggle)
node-gulp 4.0.2%2B~cs54.26.36-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 17,596 kB
  • sloc: javascript: 1,133,545; sh: 12; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 488 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var arraySort = require('..');

var arr = [
  {one: 'w', two: 'b'},
  {one: 'z', two: 'a'},
  {one: 'x', two: 'c'},
  {one: 'y', two: 'd'},
];

function compare(prop) {
  return function (a, b) {
    return a[prop].localeCompare(b[prop]);
  };
}

var result = arraySort(arr, function (a, b) {
  return a.two.localeCompare(b.two);
});

console.log(result);
// Results in:
// [ { one: 'z', two: 'a' },
//   { one: 'w', two: 'b' },
//   { one: 'x', two: 'c' },
//   { one: 'y', two: 'd' } ]