3.0.2 • Published 6 years ago

ckeys v3.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

ckeys

Build Status js-standard-style

Return a compare function (to compare object's keys) to use in an Array's .sort() function

Installation

$ npm install --save ckeys

Usage

ckeys(key)

var ckeys = require('ckeys')

var array = [
  {text: 'a', num: 7},
  {text: 'b', num: 1},
  {text: 'c', num: 23},
  {text: 'd', num: 79}
]

array.sort(ckeys('num'))

/*

[ { text: 'b', num: 1 },
  { text: 'a', num: 7 },
  { text: 'c', num: 23 },
  { text: 'd', num: 79 } ]

*/

array.sort(ckeys('num', true))

/*

[ { text: 'd', num: 79 },
  { text: 'c', num: 23 },
  { text: 'a', num: 7 },
  { text: 'b', num: 1 } ]

*/
3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

7 years ago

2.0.0

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago