Have ideas to improve npm?Join in the discussion! »

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

    2.4.3 • Public • Published

    doublylinked

    NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

    About

    Doubly linked list implementation for JavaScript with iterator and array-like interface

    Installation

    $ npm install doublylinked [--save]

    Constructor

    const list = new DoublyLinked([element1[, ..[, elementN]]]);
    Parameters
    • elementN : The elements will list contains

    Methods

    DoublyLinked.prototype.concat()

    Merges cursor list with and given lists/values into new list.

    list.concat(otherList1[, element1[, ...[otherList2]]])

    Parameters
    • valueN : Lists and/or values to concatenate into a new list

    • Return value : A new DoublyLinked instance

    DoublyLinked.prototype.entries()

    Returns the iterator object contains entries

    list.entries()

    Parameters
    • Return value : A new iterator object.

    DoublyLinked.prototype.every()

    Tests whether all elements in the list pass the test implemented by the provided function (from left to right)

    list.every(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • currentValue : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : true if the callback function returns a truthy value for every list element; otherwise, false

    DoublyLinked.prototype.everyRight()

    Tests whether all elements in the list pass the test implemented by the provided function (from right to left)

    list.everyRight(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • currentValue : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : true if the callback function returns a truthy value for every list element; otherwise, false

    DoublyLinked.prototype.filter()

    Creates a new list with all elements that pass the test implemented by the provided function

    list.filter(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • element : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : A new list with the elements that pass the test

    DoublyLinked.prototype.find()

    Returns the value of the first element in the list that satisfies the provided testing function. Otherwise undefined is returned

    list.find(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • element : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : A value in the list if an element passes the test; otherwise, undefined

    DoublyLinked.prototype.forEach()

    Executes a provided function once for each list element (from left to right)

    list.forEach(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • element : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : Value to use as this when executing callback

    DoublyLinked.prototype.forEachRight()

    Executes a provided function once for each list element (from right to left)

    list.forEachRight(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • element : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : Value to use as this when executing callback

    DoublyLinked.prototype.includes()

    Determines whether an list includes a certain element, returning true or false as appropriate

    list.includes(searchElement[, fromIndex])

    Parameters
    • searchElement : The element to search for

    • fromIndex : The position in this list at which to begin searching for searchElement. A negative value searches from the index of list.length + fromIndex by asc. Defaults to 0.

    • Return value : true if the searchElement found in the list; otherwise, false

    DoublyLinked.prototype.insert()

    Adds one or more elements right after the cursor node of the list and returns the new length of the list

    list.insert(element1[, ...[, elementN]])

    Parameters
    • elementN : The elements to add right after the cursor

    • Return value : The new length of the list

    DoublyLinked.prototype.join()

    Adds one or more elements right after the cursor node of the list and returns the new length of the list

    list.join([separator])

    Parameters
    • separator : Specifies a string to separate each pair of adjacent elements of the list

    • Return value : A string with all list elements joined. If length is 0, the empty string is returned

    DoublyLinked.prototype.map()

    Creates a new list with the results of calling a provided function on every element in the calling list

    list.map(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • currentValue : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : A new list with each element being the result of the callback function

    DoublyLinked.prototype.next()

    Moves cursor to the next and returns its value

    list.next()

    Parameters
    • Return value : Returns value of next node to the cursor. If cursor reaches to the end it returns undefined

    DoublyLinked.prototype.prev()

    Moves cursor to the previous and returns its value

    list.prev()

    Parameters
    • Return value : Returns value of previous node to the cursor. If cursor reaches to the head it returns undefined

    DoublyLinked.prototype.pop()

    Removes the last element from the list and returns that element

    list.pop()

    Parameters
    • Return value : The removed element from the list; undefined if the list is empty.

    DoublyLinked.prototype.push()

    Adds one or more elements to the end of the list and returns the new length of the list

    list.push(element1[, ...[, elementN]])

    Parameters
    • elementN : The elements to add to the end of the list

    • Return value : The new length of the list

    DoublyLinked.prototype.reduce()

    Applies a function against an accumulator and each element in the list (from left-to-right) to reduce it to a single value

    list.reduce(callback[, initialValue])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • accumulator : The accumulator accumulates the callback's return values; it is the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.

      • currentValue : The current element being processed in the list

      • currentIndex : The index of the current element being processed in the list

      • list : The list every was called upon

    • initialValue : Value to use as the first argument to the first call of the callback

    • Return value : The value that results from the reduction

    DoublyLinked.prototype.reduceRight()

    Applies a function against an accumulator and each element in the list (from right-to-left) to reduce it to a single value

    list.reduceRight(callback[, initialValue])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • accumulator : The accumulator accumulates the callback's return values; it is the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.

      • currentValue : The current element being processed in the list

      • currentIndex : The index of the current element being processed in the list

      • list : The list every was called upon

    • initialValue : Value to use as the first argument to the first call of the callback

    • Return value : The value that results from the reduction

    DoublyLinked.prototype.reset()

    Resets cursor to head

    list.reset()

    Parameters
    • Return value : Returns the DoublyLinked instance which this method is called

    DoublyLinked.prototype.reverse()

    Reverses a list in place. The first array element becomes the last, and the last list element becomes the first

    list.reverse()

    Parameters
    • Return value : Returns the DoublyLinked instance which this method is called

    DoublyLinked.prototype.shift()

    Removes the first element from the list and returns that element

    list.shift()

    Parameters
    • Return value : The removed element from the list; undefined if the list is empty

    DoublyLinked.prototype.some()

    Tests whether all elements in the list pass the test implemented by the provided function (from left to right)

    list.some(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • currentValue : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : Value to use as this when executing callback

    DoublyLinked.prototype.someRight()

    Tests whether all elements in the list pass the test implemented by the provided function (from right to left)

    list.someRight(callback[, thisArg])

    Parameters
    • callback : Function to test for each element, taking three arguments:

      • currentValue : The current element being processed in the list

      • index : The index of the current element being processed in the list

      • list : The list every was called upon

    • thisArg : Value to use as this when executing callback

    • Return value : Value to use as this when executing callback

    DoublyLinked.prototype.toArray()

    Returns a new array containing elements of the list

    list.toArray()

    Parameters
    • Return value : A new Array instance contains elements of the list

    DoublyLinked.prototype.toString()

    Returns a string representing the specified list and its elements

    list.toString()

    Parameters
    • Return value : Returns a string representing the specified list and its elements.

    DoublyLinked.prototype.unshift()

    Adds one or more elements to the beginning of the list the new length of the list

    list.unshift(element1[, ...[, elementN]])

    Parameters
    • elementN : The elements to add to the front of the list

    • Return value : The new length of the list

    DoublyLinked.prototype[@@iterator]

    Returns the iterator object contains entries

    const iterator = list[Symbol.iterator]()

    for (const val in list) {
      ...
    }
    Parameters
    • Return value : Returns the iterator object contains entries

    Properties

    cursor

    Returns current located node of the list

    head

    Returns first node of the list

    length

    Returns the element count of the list

    head

    Returns last node of the list

    Node Compatibility

    • node >= 6.0;

    License

    MIT

    Install

    npm i doublylinked

    DownloadsWeekly Downloads

    671

    Version

    2.4.3

    License

    MIT

    Unpacked Size

    38.7 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar