The size() function returns the number of elements in an array.
The size of the elements array.
Protected
_getTime 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 toArray function returns a copy of the elements in an array.
An array of type E.
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 stack containing elements from the original stack that satisfy
a given predicate function.
The predicate
parameter is a callback function that takes three arguments:
the current element being iterated over, the index of the current element, and the stack itself.
It should return a boolean value indicating whether the element should be included in the filtered
stack 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 filter
method is returning a new Stack
object that contains the elements that
satisfy the given predicate function.
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)
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(n)
The map
function takes a callback function and applies it to each element in the stack,
returning a new stack with the results.
The callback parameter is a function that will be called for each element in the stack. It takes three arguments: the current element, the index of the element, and the stack itself. It should return a new value that will be added to the new stack.
Optional
toElementFn: ((rawElement: RM) => EM)The toElementFn
parameter is an optional function that can be used to
transform the raw element (RM
) into a new element (EM
) before pushing it into the new stack.
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 Stack object with elements of type EM and raw elements of type RM.
Time Complexity: O(1) Space Complexity: O(1)
The pop
function removes and returns the last element from an array, or returns undefined if the array is empty.
The pop()
method is returning the last element of the array _elements
if the array is not empty. If the
array is empty, it returns undefined
.
Time Complexity: O(1) Space Complexity: O(1)
The push function adds an element to the stack and returns the updated stack.
The parameter "element" is of type E, which means it can be any data type.
The push
method is returning the updated Stack<E>
object.
Time Complexity: O(k) Space Complexity: O(1)
The function pushMany
iterates over elements and pushes them into an array after applying a
transformation function if provided.
The elements
parameter in the pushMany
function
is an iterable containing elements of type E
or R
. The function iterates over each element in
the iterable and pushes it into the data structure. If a transformation function toElementFn
is
provided, it is used to
The pushMany
function is returning an array of boolean values indicating whether each
element was successfully pushed into the data structure.
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.
Static
fromTime Complexity: O(n) Space Complexity: O(n)
The function "fromArray" creates a new Stack object from an array of elements.
The elements
parameter is an array of elements of type E
.
The method is returning a new instance of the Stack class, initialized with the elements from the input array.