Array

Run Settings
LanguageJavaScript
Language Version
Run Command
class MyArraay { constructor() { this.data = {} this.length = 0 } get(index) { if (this.length === 0) return [] return this.data[index] } push(item){ this.data[this.length] = item this.length++ return this.length } pop(){ let lastItem = this.data[this.length - 1] delete this.data[this.length - 1] this.length-- return lastItem } delete(index) { let deletedItem = this.data[index] this.shiftItem(index) return deletedItem } shiftItem(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-- } } const arr = new MyArray() console.log()
Editor Settings
Theme
Key bindings
Full width
Lines