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 deletedItem = this.data[this.length-1];
delete this.data[this.length-1];
this.length--;
return deletedItem;
}
delete(index) {
const deletedItem = this.data[index];
for(let i=index; i<this.length-1; i++) {
this.data[i] = this.data[i+1];
}
delete this.data[this.length-1];
this.length--;
return deletedItem;
}
}
const newArray = new MyArray();
newArray.push('a');
newArray.push('b');
newArray.push('c');
newArray.delete(1);
console.log(newArray);