Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- нужно реализовать паттерн chaining
- написать функцию createHash
- которая сможет работать вот так:
- createHash()
- .set('3', 2)
- .set('4', 5)
- .remove('3')
- .getValues() // {'4': 5}
- */
- class Hash {
- constructor() {
- this.obj = {};
- }
- set(key, value) {
- this.obj[key] = value;
- return this;
- }
- remove(key) {
- delete this.obj[key];
- return this;
- }
- getValues() {
- return this.obj;
- }
- };
- createHash = () => {
- return new Hash();
- }
- console.log(createHash().set('3', 2).set('4', 5).remove('3').getValues())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement