javascript/custom-class 썸네일형 리스트형 Javascript Queue 구현하기 class Queue { constructor() { this.storage = {}; this.firstIndex = 0; this.lastIndex = 0; } add(value) { if(this.size() === 0) { this.storage['0'] = value; } else { this.lastIndex++; this.storage[this.lastIndex] = value; } } popLeft() { let temp; if(this.firstIndex === this.lastIndex) { temp = this.storage[this.firstIndex]; delete this.storage[this.firstIndex]; this.firstIndex = 0; this.lastInde.. 더보기 Javascript Stack 구현하기 class Stack { constructor(items) { this.index = 0; this.storage = {}; if (items) { const { storage, index } = items.reduce( (obj, curVal) => { obj.storage[++obj.index] = curVal; return obj; }, { storage: {}, index: 0 }, ); this.storage = storage; this.index = index; } } push = (item) => { this.storage[++this.index] = item; }; pop = () => { // 스택에 데이터가 없는 경우 if (this.index === 0) { return undefin.. 더보기 이전 1 다음