Home Reference Source
import List from 'listas/src/List.js'
public class | version 1.1.0 | since 0.1.0 | source

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

add(data: any, i: number): List

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

delete(i: number): List

since 0.1.0
public

deleteFirst(): List

since 0.1.0
public

deleteLast(): List

since 0.1.0
public

forEach(callback: function(value: any, i: number, vec: array))

since 0.1.0
public

indexOf(key: any, comparer: function(key: any, value: any)): number

since 0.2.0
public

isEmpty(): List

since 0.1.0
public

map(callback: function(value: any, i: number, vec: array)): List

since 0.1.0
public
since 0.1.0
public

sort(comparer: function(key: any, value: any)): List

since 0.2.0
public

toArray(): Array<any>

since 0.2.0
public
since 0.1.0
public

toString(): *

since 0.1.0
Private Methods
private

builder(array: Array): *

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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 clear() since 0.1.0 source

Example:

list.clear();

public delete(i: number): List since 0.1.0 source

Params:

NameTypeAttributeDescription
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

Params:

NameTypeAttributeDescription
callback function(value: any, i: number, vec: array)

this is a callback function that will be execute for every element in the list, it should not mutated the element of the list

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:

NameTypeAttributeDescription
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

Return:

number

the index of the element or -1 if the element isn't in the list

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

Params:

NameTypeAttributeDescription
callback function(value: any, i: number, vec: array)

this is a callback function that will be execute for every element in the list, and it should mutated the element of the list

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 size(): number since 0.1.0 source

Return:

number

0 if the list is empty or an positive integer representing the list size

Example:

let boolean = list.isEmpty();

public sort(comparer: function(key: any, value: any)): List since 0.2.0 source

Params:

NameTypeAttributeDescription
comparer function(key: any, value: any)

a function that allow the library to decided what element should be put first

Return:

List

an new instance of the class with the list sorted;

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 toJSON(): object since 0.1.0 source

Return:

object

null if the list is empty or an object representing the list

Example:

let json = list.toJSON();

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();

Private Methods

private builder(array: Array): * since 0.1.0 source

Params:

NameTypeAttributeDescription
array Array

Return:

*