Here is the constructor function along with a push method
function Erray() {
this.storage = {};
this.index = 0;
}
Erray.prototype.push = function(value) {
this.storage[this.index++] = value;
}
I also made the 'add' method below...
Erray.prototype.add = function(index, value) {
for (let i = index ; i <= this.storage.length; i++) {
if (i = index) {
break;
}
this.storage[i] = this.storage[i-1]
}
this.storage[index] = value;
}
The problem is when I try to call it, I get "array.add is not a function"... Here are the calls I made to test...
let array = new Erray;
array.push(1)
array.push(2)
array.push(3)
array.add(1,1)
Why is it saying it isn't a function?
function Erray() {
this.storage = {};
this.index = 0;
}
Erray.prototype.push = function(value) {
this.storage[this.index++] = value;
}
Erray.prototype.add = function(index, value) {
for (let i = index; i <= this.storage.length; i++) {
if (i = index) {
break;
}
this.storage[i] = this.storage[i - 1]
}
this.storage[index] = value;
}
let array = new Erray;
array.push(1)
array.push(2)
array.push(3)
array.add(1, 1)
console.log('done');