@romainfieve/doubly-linked-list-navigator
v1.0.7
Published
A TypeScript library extending the [doubly-linked-list](https://github.com/rfieve/doubly-linked-list) with navigation.
Downloads
4
Maintainers
Readme
✌️🔗🧭 doubly-linked-list-navigator
A TypeScript library extending the doubly-linked-list with navigation.
Table of Content
Installation
yarn add @romainfieve/doubly-linked-list-navigator
or
npm install @romainfieve/doubly-linked-list-navigator
Usage
const arr = [10, 32, 13, 2, 89, 5, 50];
const compare = (a: number, b: number) => a - b;
const dllNav = new DoubleLinkedListNavigator(arr, compare);
// Schema of "dllNav"
// 2 <-> 5 <-> 10 <-> 13 <-> 32 <-> 50 <-> 89
dllNav
.goTo(13) // .current.data === 13
.go(2) // .current.data === 50
.go(-2); // .current.data === 13
.goPrev() // .current.data === 10
.goNext() // .current.data === 13
.goTail() // .current.data === 89
.goHead() // .current.data === 2
.goAt(1) // .current.data === 5
.current // { data: 5, next: ...}