Sort an item in a collection relative to other items based on it's before/after attribute
$ npm install beforesort
Specify the object to sort and the collection it is in. Use options to set what kind of sorting to do and what keys to compare.
type: (defaults to 'before') choose 'before' or 'after'
compareKey: (defaults to 'id') The attribute that identifies unqiue objects (it's ID)
key: (defaults to the value of
type which will be 'before' unless specified) The key to tell what object this object should be sorted relative to.
var checkPosition =var collection =id: 1 name: "First item"id: 2 name: "Second item"id: 3 name: "Third item"id: 4 name: "Fourth item"var newItem5 =id: 5name: "Inserted item before third item"before: 3collection