The head
function returns the first node of a singly linked list.
The method is returning either a SinglyLinkedListNode object or undefined.
The function returns the size of an object.
The size of the object, which is a number.
The tail
function returns the last node of a singly linked list.
The method is returning either a SinglyLinkedListNode object or undefined.
The function returns the _toElementFn property, which is a function that converts a raw element to a specific type.
The function get toElementFn()
is returning either a function that takes a raw element
rawElement
of type R
and returns an element E
, or undefined
if no function is assigned to
_toElementFn
.
Protected
_ensureThe function _ensureNode
ensures that the input is a valid node and returns it, creating a new
node if necessary.
The elementOrNode
parameter can be either
an element of type E
or a SinglyLinkedListNode
containing an element of type E
.
A SinglyLinkedListNode
Protected
_ensureThe function _ensurePredicate
in TypeScript ensures that the input is either a node, a predicate
function, or a value to compare with the node's value.
elementNodeOrPredicate - The elementNodeOrPredicate
parameter can be one of the following types:
A function is being returned. If the input elementNodeOrPredicate
is already a node, a
function is returned that checks if a given node is equal to the input node. If the input is a
predicate function, it is returned as is. If the input is neither a node nor a predicate function,
a function is returned that checks if a given node's value is equal to the input
Protected
_getProtected
_isThe _isPredicate function in TypeScript checks if the input is a function that takes a SinglyLinkedListNode as an argument and returns a boolean.
elementNodeOrPredicate - The elementNodeOrPredicate
parameter can be one of the following types:
The _isPredicate method is returning a boolean value based on whether the elementNodeOrPredicate parameter is a function or not. If the elementNodeOrPredicate is a function, the method will return true, indicating that it is a predicate function. If it is not a function, the method will return false.
Time Complexity: O(n) Space Complexity: O(1)
The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
Rest
...args: any[]The args
parameter in the code snippet represents a rest parameter. It
allows the function to accept any number of arguments as an array. In this case, the args
parameter is used to pass any number of arguments to the _getIterator
method.
Time Complexity: O(n) Space Complexity: O(1)
The addAfter
function in TypeScript adds a new element or node after an existing element or node
in a singly linked list.
existingElementOrNode can be either an element of type E or a SinglyLinkedListNode of type E.
The newElementOrNode
parameter in the
addAfter
method represents the element or node that you want to add after the existing element
or node in a singly linked list. This parameter can be either the value of the new element or a
reference to a SinglyLinkedListNode
containing
The addAfter
method returns a boolean value - true
if the new element or node was
successfully added after the existing element or node, and false
if the existing element or node
was not found.
Time Complexity: O(n) Space Complexity: O(1)
The addAt
function inserts a new element or node at a specified index in a singly linked list.
The index
parameter represents the position at which you want to add a
new element or node in the linked list. It is a number that indicates the index where the new
element or node should be inserted.
The newElementOrNode
parameter in the
addAt
method can be either a value of type E
or a SinglyLinkedListNode<E>
object. This
parameter represents the element or node that you want to add to the linked list at the specified
index.
The addAt
method returns a boolean value - true
if the element or node was
successfully added at the specified index, and false
if the index is out of bounds.
Time Complexity: O(n) Space Complexity: O(1)
The function addBefore
in TypeScript adds a new element or node before an existing element or
node in a singly linked list.
existingElementOrNode represents the element or node in the linked list before which you want to add a new element or node.
The newElementOrNode
parameter in the
addBefore
method represents the element or node that you want to insert before the existing
element or node in the linked list. This new element can be of type E
or a
SinglyLinkedListNode<E>
.
The addBefore
method returns a boolean value - true
if the new element or node was
successfully added before the existing element or node, and false
if the operation was
unsuccessful.
Time Complexity: O(n) Space Complexity: O(1)
The function at
returns the value at a specified index in a linked list, or undefined if the index is out of range.
The index parameter is a number that represents the position of the element we want to retrieve from the list.
The method at(index: number): E | undefined
returns the value at the specified index in the linked list, or
undefined
if the index is out of bounds.
Time Complexity: O(n)
Space Complexity: O(n)
The clone
function returns a new instance of the LinkedListQueue
class with the same values as
the current instance.
The clone()
method is returning a new instance of LinkedListQueue
with the same
values as the original LinkedListQueue
.
Time Complexity: O(n) Space Complexity: O(1)
The function countOccurrences
iterates through a singly linked list and counts the occurrences
of a specified element or nodes that satisfy a given predicate.
The elementOrNode
parameter in the countOccurrences
method can accept three types of values:
The countOccurrences
method returns the number of occurrences of the specified element,
node, or predicate function in the singly linked list.
Time Complexity: O(n) Space Complexity: O(1)
The delete function removes a node with a specific value from a singly linked list.
The elementOrNode
parameter can accept either a value of type E
or a SinglyLinkedListNode<E>
object.
The delete
method returns a boolean value. It returns true
if the value or node is found and
successfully deleted from the linked list, and false
if the value or node is not found in the linked list.
Time Complexity: O(n) Space Complexity: O(1)
The deleteAt
function removes an element at a specified index from a linked list and returns the removed element.
The index parameter represents the position of the element that needs to be deleted in the data structure. It is of type number.
The method deleteAt
returns the value of the node that was deleted, or undefined
if the index is out of
bounds.
Time Complexity: O(n) Space Complexity: O(1)
The every
function checks if every element in the array satisfies a given predicate.
The predicate
parameter is a callback function that takes three arguments:
the current element being processed, its index, and the array it belongs to. It should return a
boolean value indicating whether the element satisfies a certain condition or not.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the predicate
function. If thisArg
is provided, it will be
passed as the this
value to the predicate
function. If thisArg
is
The every
method is returning a boolean value. It returns true
if every element in
the array satisfies the provided predicate function, and false
otherwise.
Time Complexity: O(n) Space Complexity: O(n)
The filter
function creates a new SinglyLinkedList by iterating over the elements of the current
list and applying a callback function to each element to determine if it should be included in the
filtered list.
The callback parameter is a function that will be called for each element in the list. It takes three arguments: the current element, the index of the current element, and the list itself. The callback function should return a boolean value indicating whether the current element should be included in the filtered list or not
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the callback
function. If thisArg
is provided, it will be
passed as the this
value to the callback
function. If thisArg
is
The filter
method is returning a new SinglyLinkedList
object that contains the
elements that pass the filter condition specified by the callback
function.
Time Complexity: O(n) Space Complexity: O(1)
The find
function iterates over the elements of an array-like object and returns the first
element that satisfies the provided callback function.
The callbackfn parameter is a function that will be called for each element in the array. It takes three arguments: the current element being processed, the index of the current element, and the array itself. The function should return a boolean value indicating whether the current element matches the desired condition.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the callbackfn
function. If thisArg
is provided, it will
be passed as the this
value to the callbackfn
function. If thisArg @returns The
findmethod returns the first element in the array that satisfies the provided callback function. If no element satisfies the callback function,
undefined` is returned.
Time Complexity: O(n) Space Complexity: O(1)
The forEach
function iterates over each element in an array-like object and calls a callback
function for each element.
The callbackfn parameter is a function that will be called for each element in the array. It takes three arguments: the current element being processed, the index of the current element, and the array that forEach was called upon.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as this
when executing the callbackfn
function. If thisArg
is provided, it will
be passed as the this
value to the callbackfn
function. If `thisArg
Time Complexity: O(n) Space Complexity: O(1)
This function searches for a specific element in a singly linked list based on a given node or predicate.
elementNodeOrPredicate - The elementNodeOrPredicate
parameter in the get
method can be one of
the following types:
The get
method returns the value of the first node in the singly linked list that
satisfies the provided predicate function. If no such node is found, it returns undefined
.
Time Complexity: O(n) Space Complexity: O(1)
The function getNode
in TypeScript searches for a node in a singly linked list based on a given
element, node, or predicate.
elementNodeOrPredicate - The elementNodeOrPredicate
parameter in the getNode
method can be one
of the following types:
The getNode
method returns either a SinglyLinkedListNode<E>
if a matching node is
found based on the provided predicate, or it returns undefined
if no matching node is found or
if the input parameter is undefined
.
Time Complexity: O(n) Space Complexity: O(1)
The function getNodeAt
returns the node at a given index in a singly linked list.
The index
parameter is a number that represents the position of the node we want to
retrieve from the linked list. It indicates the zero-based index of the node we want to access.
The method getNodeAt(index: number)
returns a SinglyLinkedListNode<E>
object if the node at the
specified index exists, or undefined
if the index is out of bounds.
Time Complexity: O(n) Space Complexity: O(1)
The function checks if a given element exists in a collection.
The parameter "element" is of type E, which means it can be any type. It represents the element that we want to check for existence in the collection.
a boolean value. It returns true if the element is found in the collection, and false otherwise.
Time Complexity: O(n) Space Complexity: O(1)
The indexOf
function in TypeScript searches for a specific element or node in a singly linked
list and returns its index if found.
elementNodeOrPredicate - The elementNodeOrPredicate
parameter in the indexOf
method can be one
of the following types:
The indexOf
method returns the index of the first occurrence of the element that
matches the provided predicate in the singly linked list. If no matching element is found, it
returns -1.
Time Complexity: O(1) Space Complexity: O(1)
The function isNode
in TypeScript checks if the input is an instance of SinglyLinkedListNode
.
elementNodeOrPredicate - The elementNodeOrPredicate
parameter in the isNode
function can be
one of the following types:
The isNode
function is checking if the elementNodeOrPredicate
parameter is an
instance of SinglyLinkedListNode<E>
. If it is, the function returns true
, indicating that the
parameter is a SinglyLinkedListNode<E>
. If it is not an instance of SinglyLinkedListNode<E>
,
the function returns false
.
Time Complexity: O(n) Space Complexity: O(n)
The map
function takes a callback function and returns a new SinglyLinkedList with the results
of applying the callback to each element in the original list.
The callback
parameter is a function that will be called for each element in
the original list. It takes three arguments: current
(the current element being processed),
index
(the index of the current element), and this
(the original list). It should return a
value
Optional
toElementFn: ((rawElement: RM) => EM)The toElementFn
parameter is an optional function that can be used to
convert the raw element (RR
) to the desired element type (T
). It takes the raw element as
input and returns the converted element. If this parameter is not provided, the raw element will
be used as is.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that allows you to
specify the value of this
within the callback function. It is used to set the context or scope
in which the callback function will be executed. If thisArg
is provided, it will be used as the
value of
a new instance of the SinglyLinkedList
class with the mapped elements.
Time Complexity: O(1) Space Complexity: O(1)
The push
function adds a new element or node to the end of a singly linked list.
The elementOrNode
parameter in the push
method can accept either an element of type E
or a SinglyLinkedListNode<E>
object.
The push
method is returning a boolean value, specifically true
.
Time Complexity: O(n) Space Complexity: O(1)
The reduce
function iterates over the elements of an array-like object and applies a callback
function to reduce them into a single value.
The callbackfn parameter is a function that will be called for each element in the array. It takes four arguments:
The initialValue parameter is the initial value of the accumulator. It is the value that the accumulator starts with before the reduction operation begins.
The reduce
method is returning the final value of the accumulator after iterating over
all the elements in the array and applying the callback function to each element.
Time Complexity: O(n) Space Complexity: O(1)
The "some" function checks if at least one element in a collection satisfies a given predicate.
The predicate
parameter is a callback function that takes three arguments:
value
, index
, and array
. It should return a boolean value indicating whether the current
element satisfies the condition.
Optional
thisArg: anyThe thisArg
parameter is an optional argument that specifies the value
to be used as the this
value when executing the predicate
function. If thisArg
is provided,
it will be passed as the this
value to the predicate
function. If `thisArg
a boolean value. It returns true if the predicate function returns true for any element in the collection, and false otherwise.
Time Complexity: O(1) Space Complexity: O(1)
The unshift function adds a new element or node to the beginning of a singly linked list in TypeScript.
The elementOrNode
parameter in the
unshift
method can be either an element of type E
or a SinglyLinkedListNode
containing an
element of type E
.
The unshift
method is returning a boolean value, specifically true
.
Static
fromTime Complexity: O(n) Space Complexity: O(n)
The fromArray
function creates a new SinglyLinkedList instance and populates it with the elements from the given
array.
The data
parameter is an array of elements of type E
.
The fromArray
function returns a SinglyLinkedList
object.