Quick actions

cmd+k|ctrl+k

Navigation

Languages

ArrayImplementation

Snippet info

Language

JavaScript

Visibility

public

Author

mrp123

Created

2019-01-22T08:01:55Z

Updated

2019-01-22T08:01:55Z


class MyArray{
    constructor(){
        this.length=0;
        this.data={};
    }  
    get(index){
        return this.data[index];
    }
    push(item){
        this.data[this.length]=item;
        this.length++;
        return this.length;
    }
    pop(){
        const lastItme=this.data[this.length-1];
        delete this.data[this.length-1];
        this.length--;
        return lastItme;
    
    }

}

const arr1=new MyArray();
arr1.push(2);
arr1.push(3);
arr1.push(4);
arr1.push(5);
arr1.push(6);
console.log(arr1);
INFO