JSFiddle - React, Tailwind, and code Playground
by devangkantharia
JavaScript
// Answer 1
function MyArray(a, b, c, d) {
this.push(a);
this.push(b);
this.push(c);
this.push(d);
this.add = function (a1) {
return this.push(a1);
};
Array.prototype.addAll = function (arguments) {
for (var a = 0; a < arguments.length; a++) {
arr = arguments[a];
this.push(arr);
}
}
}
MyArray.prototype = [];
var collection = new MyArray(1, 2, 3, 4);
console.log(collection instanceof Array);
console.log(collection instanceof MyArray);
console.log(collection);
console.log(collection.length);
collection.add("hello");
console.log(collection[4]);
console.log(collection.length);
collection.push("world");
console.log(collection.length); //6
console.log(collection[5]);
collection.addAll(["java", "script"]);
console.log(collection.length); //8
console.log(collection);
collection[8] = "last";
console.log(collection.length); //9
console.log(collection.pop()); //"last"
console.log(collection.length); //8
console.log(Array.prototype.addAll);