UNPKG

1.45 kBMarkdownView Raw
1<!-- DO NOT EDIT THIS FILE! THIS FILE WAS AUTOGENERATED BY TEMPLATE-MATE -->
2<!-- SEE https://github.com/angus-c/just/blob/master/CONTRIBUTING.md#readme-template -->
3
4## just-sort-by
5
6Part of a [library](https://anguscroll.com/just) of zero-dependency npm modules that do just do one thing.
7Guilt-free utilities for every occasion.
8
9[`🍦 Try it`](https://anguscroll.com/just/just-sort-by)
10
11```shell
12npm install just-sort-by
13```
14```shell
15yarn add just-sort-by
16```
17
18Produces a new array, sorted in ascending order
19
20```js
21import sortBy from 'just-sort-by';
22
23sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]
24
25sortBy([
26 {user: 'fabio', details: {city: "Milan", age: 34}},
27 {user: 'max', details: {city: "Munich", age: 29}},
28 {user: 'zacarias', details: {city: "Sao Paulo", age: 44}},
29 {user: 'robert', details: {city: "Manchester", age: 28}},
30 {user: 'klaus', details: {city: "Zurich", age: 38}},
31], function(o) {
32 return o.details.age;
33});
34
35/*
36[
37 {user: 'robert', age: 28},
38 {user: 'max', age: 29},
39 {user: 'fabio', age: 34},
40 {user: 'klaus', age: 38},
41 {user: 'zacarias', age: 44},
42]
43*/
44
45sortBy([
46 {user: 'fabio', age: 34},
47 {user: 'max', age: 29},
48 {user: 'zacarias', age: 44},
49 {user: 'robert', age: 28},
50 {user: 'klaus', age: 38},
51], 'user');
52/*
53[
54 {user: 'fabio', age: 34},
55 {user: 'klaus', age: 38},
56 {user: 'max', age: 29},
57 {user: 'robert', age: 28},
58 {user: 'zacarias', age: 44},
59]
60*/
61```