Skip to content

WebForgeOSS/sort-of

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sort-of

Sort objects by the value of their key

Build Status Coverage Status Maintainability Language grade: JavaScript tested with jest code style: prettier

Install

$ npm install @saxjst/sort-of

Usage

const sortOf = require('@saxjst/sort-of');

const people = [
  {
    name: "alice",
    age: 15
  },
  {
    name: "bob",
    age: 9
  },
  {
    name: "aaron",
    age: 12
  },
]

sortOf(people, ['age'], 'asc');
// [
//   {
//     name: "bob",
//     age: 9
//   },
//   {
//     name: "aaron",
//     age: 12
//   },
//   {
//     name: "alice",
//     age: 15
//   }
// ]

API

sortOf(arr, [path], command) ⇒ Number[] | Object[]

Sort objects by the value of their key

Kind: global function
Returns: Number[] | Object[] - the sorted array

Param Type Default Description
arr Number[] OR Object[] the array to retrieve the value from.
[path] String[] [] the key to sort by
command String asc or desc

License

MIT © saxjst