npm.io
1.0.0 • Published 7 years ago

compare-at-paths

Licence
MIT
Version
1.0.0
Deps
3
Size
4 kB
Vulns
0
Weekly
0
Stars
1

compare-at-paths

create a compare function that compares given paths into an object.

example

[
  {foo: true, bar: {baz: 1}},
  {foo: true, bar: {baz: 3}},
  {foo: true, bar: {baz: 2}},
  {foo: false, bar: {baz: 1}}
].sort(Compare([['bar', 'baz'], ['foo']]))

output will be

[
  {foo: false, bar: {baz: 1}},
  {foo: true, bar: {baz: 1}},
  {foo: true, bar: {baz: 2}},
  {foo: true, bar: {baz: 3}}
]

if you want a field to be in decending order, use {$reverse: [path...]}

License

MIT