Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Реализовать свой Map
- * @constructor
- */
- function XMap() {
- const buf = Object.create(null);
- this.set = (key, value) => {
- buf[key] = value;
- };
- this.get = (key) => {
- return buf[key];
- };
- this.has = (key) => {
- return buf[key] !== undefined;
- };
- this.remove = (key) => {
- delete buf[key];
- };
- }
- // Проверка
- const map = new XMap();
- const objKey = {foo: true};
- map.set(123, 'ok');
- map.set(objKey, 'fail');
- map.has(objKey) && map.set(objKey, 'wow');
- console.log(map.get(123)); // "ok"
- console.log(map.get(objKey)); // "wow"
- map.remove(123);
- console.log(map.has(123)); // false
- map.has('toString');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement