Quick actions

cmd+k|ctrl+k

Navigation

Languages

Data Structure

Snippet info

Language

JavaScript

Visibility

public

Author

expertsanoy

Created

2023-05-30T02:15:37.223769Z

Updated

2023-05-30T02:15:37.223769Z

class myArray{
    constructor(){
        this.data = {};
        this.length = 0;
    }
    get(index){
        return this.data[index]
    }
    push(item){
        this.data[this.length] = item;
        this.length++;
    }
    
    delete(index){
        this._shiftItem(index)
    }
    _shiftItem(index){
        for(let i=index; i<this.length; i++){
            this.data[index] = this.data[index+1]
        }
        delete this.data[this.length-1]
        this.length--;
    }
    
}
const array1 = new myArray();
array1.push('hello');
array1.push('world');
array1.push('yonas');

console.log('original: ', array1);
array1.delete(1);
console.log('final: ', array1);
INFO