1.0.10 • Published 2 years ago

traverselinkedlist v1.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years 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

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago