1.0.10 • Published 1 year ago

traverselinkedlist v1.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Perform operations on linked list

Sort

Perform sort operations on a list of objects that are linked together in the following manner.

[
  { id: 1, nextItem: 2, previousItem: null },
  { id: 2, nextItem: 3, previousItem: 1 },
  { id: 3, nextItem: null, previousItem: 2 },
]

nextItem and previousItem are properties containing id of the item that next or previous in the list.

Get first item

Get the first item in the list

const items = [
  { id: 2, nextItem: 3, previousItem: 1 },
  { id: 1, nextItem: 2, previousItem: null },
  { id: 3, nextItem: null, previousItem: 2 },
]

const firstItem = getFirstItem(items, 'previousItem', 'nextItem');
// it will return
// { id: 1, nextItem: 2, previousItem: null }
1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago