Stack
by Vladymyr Shevchuk
JavaScript
class Stack {
constructor() {
const store = new Map();
this.get = key => store.delete(key);
this.set = (key, value) => {
store.set(key, value);
return store.get(key);
};
// TODO: check why js not create copy
this.getStore = function() {
return (function(storeCopy) {
return storeCopy;
}(store));
};
}
}
const stack = new Stack();
stack.set('foo', 'bar');
stack.set('baz', 'bar');
stack.get('foo');
let foo = stack.getStore();
foo.set('riba', 'riba');
console.log(foo);
console.log(foo === stack.getStore());