List
List class, this class allow you to use a LinkedList DS based on an array
Example:
let list = new List();
Constructor Summary
Public Constructor | ||
public |
|
since 0.1.0 |
Member Summary
Private Members | ||
private |
array: *[] |
since 0.1.0 |
Method Summary
Public Methods | ||
public |
|
since 0.1.0 |
public |
addAll(collection: any[]): List |
since 0.1.0 |
public |
addFirst(data: any): List |
since 0.1.0 |
public |
addLast(data: any): List |
since 0.1.0 |
public |
clear() |
since 0.1.0 |
public |
|
since 0.1.0 |
public |
deleteFirst(): List |
since 0.1.0 |
public |
deleteLast(): List |
since 0.1.0 |
public |
|
since 0.1.0 |
public |
|
since 0.2.0 |
public |
isEmpty(): List |
since 0.1.0 |
public |
|
since 0.1.0 |
public |
|
since 0.1.0 |
public |
|
since 0.2.0 |
public |
|
since 0.2.0 |
public |
|
since 0.1.0 |
public |
toString(): * |
since 0.1.0 |
Private Methods | ||
private |
|
since 0.1.0 |
Public Constructors
public constructor() since 0.1.0 source
Private Members
private array: *[] since 0.1.0 source
Public Methods
public add(data: any, i: number): List since 0.1.0 source
Params:
Name | Type | Attribute | Description |
data | any | the element than you whan to add to the list |
|
i | number | the index value in which to add the element [0, list.size()) |
Return:
List | a new instance of the class with the elements of the other list and the new element added |
Throw:
Error001 |
when shit go bad |
Error100 |
when data is null |
Error101 |
when data is undefined |
Error110 |
when the index is null |
Error111 |
when the index is undefined |
Error112 |
when the index is Not a Number |
Example:
let l = list.add(1, 0);
public addAll(collection: any[]): List since 0.1.0 source
Params:
Name | Type | Attribute | Description |
collection | any[] | an Array of elements to add |
Return:
List | a new instance of the class with the elements of the other list and the new elements added |
Throw:
Error001 |
when shit go bad |
Error102 |
when collection is null |
Error103 |
when collection is undefined |
Error104 |
when collection is not an array |
Example:
let l = list.addAll([1,'a',3]);
public addFirst(data: any): List since 0.1.0 source
Params:
Name | Type | Attribute | Description |
data | any | the element than you whan to add to the list |
Return:
List | a new instance of the class with the elements of the other list and the new element added |
Throw:
Error001 |
when shit go bad |
Error100 |
when data is null |
Error101 |
when data is undefined |
Example:
let l = list.addFirst(1);
public addLast(data: any): List since 0.1.0 source
Params:
Name | Type | Attribute | Description |
data | any | the element than you whan to add to the list |
Return:
List | a new instance of the class with the elements of the other list and the new element added |
Throw:
Error001 |
when shit go bad |
Error100 |
when data is null |
Error101 |
when data is undefined |
Example:
let l = list.addLast(1);
public delete(i: number): List since 0.1.0 source
Params:
Name | Type | Attribute | Description |
i | number | the index of the element to eliminate [0, list.size()) |
Return:
List | null if the list is empty a new instance of the class with the elements of the other list except the element i |
Throw:
Error001 |
when shit go bad |
Error110 |
when i is null |
Error111 |
when i is undefined |
Error112 |
when i is Not a Number |
Error113 |
when i is bigger than the list size |
Example:
let l = list.delete(0);
public deleteFirst(): List since 0.1.0 source
Return:
List | null is the list is empty or a new instance of the class with the elements of the other list except from the first |
Example:
let l = list.deleteFirst();
public deleteLast(): List since 0.1.0 source
Return:
List | null is the list is empty or a new instance of the class with the elements of the other list except from the first |
Example:
let l = list.deleteLast();
public forEach(callback: function(value: any, i: number, vec: array)) since 0.1.0 source
Throw:
Error001 |
when shit go bad |
Error200 |
when the list is empty |
Error300 |
when callback is not a function |
Example:
list.forEach((x,i,vec) => {
console.log(`Value: ${x}, Index: ${i}`);
});
public indexOf(key: any, comparer: function(key: any, value: any)): number since 0.2.0 source
Params:
Name | Type | Attribute | Description |
key | any | the element that we are searching in the list |
|
comparer | function(key: any, value: any) | a function that return true when the two values are equals |
Throw:
Error001 |
When shits go bad |
Error401 |
When the key is null |
Error402 |
When the key is undefined |
Error501 |
When the comparer is null |
Error503 |
When the comparer is not a function |
Example:
let i = list.indexOf(3);
let j = list.indexOf(3, (x, y) => x === y["x"]);
public isEmpty(): List since 0.1.0 source
Return:
List | true if the list is empty or false otherwaise |
Example:
let boolean = list.isEmpty();
public map(callback: function(value: any, i: number, vec: array)): List since 0.1.0 source
Return:
List | An instance of the class with the mutated elements |
Throw:
Error001 |
when shit go bad |
Error200 |
when the list is empty |
Error300 |
when callback is not a function |
Example:
let l = list.map((x,i,vec) => x * x);
public sort(comparer: function(key: any, value: any)): List since 0.2.0 source
Params:
Name | Type | Attribute | Description |
comparer | function(key: any, value: any) | a function that allow the library to decided what element should be put first |
Throw:
Error501 |
when the comparer is null |
Error503 |
when the comparer isn't a function |
Error001 |
when shits go bad |
Example:
let l = list.sort((x, y) => y > x);
public toArray(): Array<any> since 0.2.0 source
Return:
Array<any> | return an array with the elements contained in the list or null if the list is empty |
Example:
let vec = list.toArray();
public toString(): * since 0.1.0 source
Return:
* | null if the list is empty or a string representig the list |
Example:
let string = list.string();