1.4.0 • Published 3 years ago

prev-sort v1.4.0

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

Prev Sort

Sort a collection based on each item knowing the item before it

Installation

npm install --save prev-sort

Usage

import prevSort from 'prev-sort'

const array = [
  { id: 4, previousId: 3 },
  { id: 2, previousId: 1 },
  { id: 3, previousId: 2 },
  { id: 1, previousId: null },
]

const sortedArray = prevSort(array, {
  getId: (item) => item.id,
  getPreviousId: (item) => item.previousId,
})

/*
[
  { id: 1, previousId: null },
  { id: 2, previousId: 1 },
  { id: 3, previousId: 2 },
  { id: 4, previousId: 3 },
]
*/
1.4.0

3 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago