any value matching T
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
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
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
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
Clears the list of all values.
const dll = DLinkedList.fromArray([1,2,3,4,5])
dll.clear() // []
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
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
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]
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
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}
Creates a new DLinkedList from an array of values.
const dll = new DLinkedList<number>()
dll.fromArray([1,2,3,4,5])
Any Array of values matching type T
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 the head node directly.
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]
Inserts data after the provided node.
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]
Inserts data before the node provided node
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]
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]
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]
any value matching T
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
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
Removes the first value that predicate function returns truthy for
const dll = DLinkedList.fromArray([1,1,2,3,4,5])
dll.remove(v => v === 1) // [1,2,3,4,5]
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]
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 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 the tail node directly.
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}]
Accepts an array and returns a DLinkedList instance.
Generated using TypeDoc
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]