Created
August 1, 2018 13:39
-
-
Save w3cj/c103c0393440e200598060e61d7769f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array { | |
constructor() { | |
this.length = 0; | |
} | |
push(value) { | |
this[this.length] = value; | |
this.length++; | |
} | |
pop() { | |
const value = this[this.length - 1]; | |
this.length--; | |
return value; | |
} | |
forEach(fn) { | |
// iterate over the array | |
// invoke fn with each value in the array | |
} | |
} | |
const arr = new Array(); | |
arr.push(1); | |
console.log(arr.length); | |
arr.push(10); | |
console.log(arr.length); | |
console.log(arr[0]); // -> 1 | |
console.log(arr[1]); // -> 10 | |
console.log(arr.pop()); // -> 10 | |
console.log(arr.length); // -> 1 | |
arr.forEach((value, index, array) => { | |
console.log(value, index, array); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment