January 2018
Intermediate to advanced
332 pages
7h 36m
English
Implementing a stack is a rather easy task. We will follow a series of steps, where we will use the ES6 syntax, as follows:
class Stack { constructor() { }}
const sKey = {};const items = new WeakMap();class Stack { constructor() { items.set(sKey, []) }}
const sKey = {};const items = new WeakMap();class Stack { constructor() { items.set(sKey, []); } push(element) { let stack = items.get(sKey); stack.push(element); } pop() { let stack = items.get(sKey) return stack.pop() } peek() { let stack = items.get(sKey); return stack[stack.length - 1]; } clear() { items.set(sKey ...
Read now
Unlock full access