traverselinkedlist
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

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 }

Readme

Keywords

none

Package Sidebar

Install

npm i traverselinkedlist

Weekly Downloads

2

Version

1.0.10

License

ISC

Unpacked Size

5.84 kB

Total Files

12

Last publish

Collaborators

  • mahinkhan