compare-func

WebJar for compare-func

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

compare-func
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

compare-func
WebJar for compare-func
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/stevemao/compare-func

Download compare-func

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/compare-func/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>compare-func</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/compare-func/
implementation 'org.webjars.npm:compare-func:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/compare-func/
implementation ("org.webjars.npm:compare-func:2.0.0")
'org.webjars.npm:compare-func:jar:2.0.0'
<dependency org="org.webjars.npm" name="compare-func" rev="2.0.0">
  <artifact name="compare-func" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='compare-func', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "compare-func" % "2.0.0"
[org.webjars.npm/compare-func "2.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : array-ify jar [1.0.0,2)
org.webjars.npm : dot-prop jar [5.1.0,6)

Project Modules

There are no modules declared in this project.

NPM version Build Status Dependency Status Coverage Status

Get a compare function for array to sort

Install

$ npm install --save compare-func

Usage

var compareFunc = require('compare-func');

// sort by an object property
[{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc('x'));
//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]

// sort by a nested object property
[{x: {y: 'b'}}, {x: {y: 'a'}}].sort(compareFunc('x.y'));
//=> [{x: {y: 'a'}}, {x: {y: 'b'}}]

// sort by the `x` propery, then `y`
[{x: 'c', y: 'c'}, {x: 'b', y: 'a'}, {x: 'b', y: 'b'}].sort(compareFunc(['x', 'y']));
//=> [{x: 'b', y: 'a'}, {x: 'b', y: 'b'}, {x: 'c', y: 'c'}]

// sort by the returned value
[{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc(function(el) {
  return el.x;
}));
//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]

API

compareFunc([property])

Returns a compare function for array to sort

property

Type: string, function or array of either

If missing it sorts on itself.

The string can be a dot path to a nested object property.

Related

  • sort-on - Sort an array on an object property

License

MIT © Steve Mao

Versions

Version
2.0.0