Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • T

Hierarchy

  • DLinkedList

Index

Properties

head_node

head_node: Node<T> = null

length

length: number = 0

tail_node

tail_node: Node<T> = null

Methods

append

  • Adds the supplied data to the end of the list.

     const dll = DLinkedList.fromArray([1,2,3,4])
     dll.append(5) // [1,2,3,4,5]

    Parameters

    • data: T

      any value matching T

    Returns DLinkedList<T>

asyncMap

  • Asynchronously returns a new DLinkedList from the values resolved by iteratee function.

    Iteratees are dispatched all at once, so use caution with large lists. If the list values are plain objects, deep clones will be supplied to iteratee.

    let dll = DLinkedList.fromArray([1,2,3,4,5]) let results = await dll.asyncMap((n) => { return new Promise((resolve) => { setTimeout(() => { resolve(n*n) }, 5000) }) }) // results === [1, 4, 9, 16, 25] 5 seconds later, not 25.

    Type parameters

    • V

    Parameters

    Returns Promise<DLinkedList<V>>

asyncMapRight

  • Asynchronously returns a new DLinkedList from the values resolved by iteratee function, in reverse order.

    Iteratees are dispatched all at once, so use caution with large lists. If the list values are plain objects, deep clones will be supplied to iteratee.

    let dll = DLinkedList.fromArray([1,2,3,4,5]) let results = await dll.asyncMapRight((n) => { return new Promise((resolve) => { setTimeout(() => { resolve(n*n) }, 5000) }) }) // results === [1, 4, 9, 16, 25] 5 seconds later, not 25

    Type parameters

    • V

    Parameters

    Returns Promise<DLinkedList<V>>

asyncReduce

  • Asynchronously reduces list values to a single value.

    let dll = DLinkedList.fromArray<number>([1,2,3,4,5])
    let results = await dll.asyncReduce((n) => {
       return new Promise((resolve) => {
         acc += n
         setTimeout(() => {
           resolve(acc)
         }, 5000)
       })
     }, 0)
    // results === 15 - 25 seconds later, not 5

    Type parameters

    • A

    Parameters

    Returns Promise<A>

asyncReduceRight

  • Asynchronously reduces list values to a single value, in reverse order.

    let dll = DLinkedList.fromArray<number>([1,2,3,4,5])
    let results = await dll.asyncReduceRight((n) => {
       return new Promise((resolve) => {
         acc -= n
         setTimeout(() => {
           resolve(acc)
         }, 5000)
       })
     }, 15)
    // results === 0 - 25 seconds later, not 5
    

    Type parameters

    • A

    Parameters

    Returns Promise<A>

clear

each

  • Runs iteratee with the cloned value found in each node, in order.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    dll.each(v => console.log(v * 2)) // 2,4,6,8,10
    

    Parameters

    Returns DLinkedList<T>

eachRight

  • Runs iteratee with the cloned value found in each node, in reverse order.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    dll.eachRight(v => console.log(v * 2)) // 10,8,6,4,2
    

    Parameters

    Returns DLinkedList<T>

filter

  • Returns all values predicate function returns truthy for. Plain objects will be deeply cloned.

    const dll = DLinkedList.fromArray([1,2,3,4,5,6,7,8,9])
    let doubled = dll.filter(v => v >= 4) // [4,5,6,7,8,9]
    

    Parameters

    Returns DLinkedList<T>

find

  • Returns the first value predicate function returns truthy for.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    let node = dll.find(v => v === 1) // 1
    

    Parameters

    Returns T | null

findNode

  • Returns the first Node predicate function returns truthy for.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    let node = dll.findNode(v => v === 1) // Node{data: 1, nextNode: Node{}, prevNode: null}
    

    Parameters

    Returns Node<T>

fromArray

  • Creates a new DLinkedList from an array of values.

     const dll = new DLinkedList<number>()
     dll.fromArray([1,2,3,4,5])

    Parameters

    • arr: T[]

      Any Array of values matching type T

    Returns DLinkedList<T>

head

  • head(): T | null
  • Returns the value stored in the first position of the list. If value is a plain object, the return value will be a deep clone of stored object.

     const dll = DLinkedList.fromArray([1,2,3,4,5])
     dll.head() // 1

    Returns T | null

headNode

  • headNode(): Node<T>

insertAfter

  • Inserts data after the first value predicate function returns truthy for.

     const dll = DLinkedList.fromArray([1,2,4,5])
     dll.insertAfter(v => v === 2, 3) // [1,2,3,4,5]
    

    Parameters

    Returns DLinkedList<T>

insertAfterNode

insertBefore

  • Inserts data before the first value predicate function returns truthy for.

     const dll = DLinkedList.fromArray([1,2,4,5])
     dll.insertAfter(v => v === 4, 3) // [1,2,3,4,5]
    

    Parameters

    Returns DLinkedList<T>

insertBeforeNode

map

  • Returns a new DLinkedList from the values returned by iteratee function. If the list values are plain objects, deep clones will be supplied to iteratee.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    let doubled = dll.map(v => v * 2) // [2,4,6,8,10]
    

    Type parameters

    • V

    Parameters

    Returns DLinkedList<V>

mapRight

  • Returns a new DLinkedList from the values returned by iteratee function, in reverse order. If the list values are plain objects, deep clones will be supplied to iteratee.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    let doubled = dll.mapRight(v => v * 2) // [10,8,6,4,2]
    

    Type parameters

    • V

    Parameters

    Returns DLinkedList<V>

prepend

  • Adds the supplied data to the front of the list.

     const dll = DLinkedList.fromArray([2,3,4,5])
     dll.prepend(1) // [1,2,3,4,5]

    Parameters

    • data: T

      any value matching T

    Returns DLinkedList<T>

reduce

  • Reduces list values to a single value.

    let dll = DLinkedList.fromArray([1,2,3,4,5])
    let results = dll.reduce((v, acc) => {
      acc += v
      return acc
    }, 0)
    
    // results === 15
    

    Type parameters

    • V

    Parameters

    Returns any

reduceRight

  • reduceRight<V>(iteratee: reduceIteratee<T, V>, accumulator: any): any
  • Reduces list values to a single value, in reverse order.

    let dll = DLinkedList.fromArray([1,2,3,4,5])
    let results = dll.reduceRight((v, acc) => {
       acc -= v
       return acc
    }, 15)
    
    // results === 0

    Type parameters

    • V

    Parameters

    Returns any

remove

removeHead

  • Removes the first value in the list. The next value will become the current head.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    dll.removeHead() // [2,3,4,5]
    

    Returns DLinkedList<T>

removeNode

removeTail

  • Removes the last value in the list. The previous value will become the current head.

    const dll = DLinkedList.fromArray([1,2,3,4,5])
    dll.removeTail() // [1,2,3,4]
    

    Returns DLinkedList<T>

tail

  • tail(): T | null
  • Returns the value stored in the last position of the list. If value is a plain object, the return value will be a deep clone of stored object.

     const dll = DLinkedList.fromArray([1,2,3,4,5])
     dll.tail() // 5

    Returns T | null

tailNode

  • tailNode(): Node<T>

toArray

  • toArray(): T[]
  • Creates an array from the values in list. If values are plain objects they will be deeply cloned.

    const objs = [{a: 1}, {a: 2}]
    const dll = DLinkedList.fromArray(objs)
    
    let cloned = dll.toArray() // [{a: 1}, {a: 2}]
    cloned[0].a = 100
    cloned[0].b = 200
    cloned // [{a: 100}, {a: 200}]
    objs // [{a: 1}, {a: 2}]
    dll.toArray() // [{a: 1}, {a: 2}]
    

    Returns T[]

Static fromArray

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc