Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript array data structure

class DS_Array{
    private data: any = {};
    private length: number = 0;

    /*
    * Yields the element from the specified index from the array;
    */
    public Get(index: number){
        if(index > this.length) return "err -> index limit exceeded";
        return this.data[index];
    }

    /*
    * Removes the last element of the array
    */
    public Pop(){
        if(this.length <= 0) return "err -> no elements in the array"
        delete this.data[this.length - 1];
        this.length--;
    }

    /*
    * Adds an element to the end of the array
    */
    public Push(item: any){
        this.data[this.length] = item;
        this.length++;
    }

    /*
    * Deletes the element from the specified index from the array;
    */
    public Delete(index: number){
        if(index > this.length) return "err -> index limit exceeded"
        delete this.data[index];
        this.ShiftIndexes(index);
    }

    /*
    * Shifts items and their indexes accordingly;
    */
    private ShiftIndexes(index: number) {
        for (let x = index; x < this.length - 1; ++x) this.data[x] = this.data[x + 1];
        delete this.data[this.length - 1];
        this.length--;
    }

    /*
    * Renders the entire data structure clear
    */
    public Clear(){
        if(this.length <= 0) return "err -> no elements left";
        for (let x = 0; x < this.length; ++x) delete this.data[x];
        this.length = 0;
    }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to collect array of objects in one value key in laravel 
Typescript :: how to checka query to return User whose first name starts with R or last name starts with D in django 
Typescript :: typescript object annotation 
Typescript :: how to call an action from another action in redux 
Typescript :: nextjs and nodemailer problem after deploy 
Typescript :: convert function to arrow function typescript 
Typescript :: typescript enum get key by value 
Typescript :: js 
Typescript :: angular jasmine tobe empty array 
Typescript :: breaks_width in r 
Typescript :: AFTER RESETTING ANGULAR FORM I AM GETTING RED INVALID FORM 
Typescript :: github:Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15 in android 
Typescript :: online ts compiler 
Typescript :: token authentication requirements for git operations 
Typescript :: fwrite() expects parameter 2 to be string, array given 
Typescript :: spritesheets in pyqt 
Cpp :: how to convert string to wchar_t in c++ 
Cpp :: add c++ 
Cpp :: select one random element of a vector in c++ 
Cpp :: how to complie with c++ 17 
Cpp :: initialize vector to all zeros c++ 
Cpp :: programs for printing pyramid patterns in c++ 
Cpp :: c++ fill array with 0 
Cpp :: have unique vector after sorting vector 
Cpp :: rapidjson write stringbuffer to file 
Cpp :: ue4 find component c++ 
Cpp :: how to make a sqlite3 object in cpp 
Cpp :: c++ nodiscard 
Cpp :: c++ read file to char buffer 
Cpp :: __lg(x) in c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =