Skip to content

Instantly share code, notes, and snippets.

@tarhunakau
Created April 19, 2019 08:01
Show Gist options
  • Save tarhunakau/6686f7592a5cb15293bf045a3f9cd85f to your computer and use it in GitHub Desktop.
Save tarhunakau/6686f7592a5cb15293bf045a3f9cd85f to your computer and use it in GitHub Desktop.
Hash function
// Добавьте в Object.prototype функцию hash, которая позволяет извлекать вложенные значения из объекта.
const obj = {
person: {
name: 'joe',
history: {
hometown: 'bratislava',
bio: {
funFact: 'I like fishing.',
},
},
},
};
obj.hash('car'); // undefined
obj.hash('person.history.bio'); // { funFact: 'I like fishing.' }
obj.hash('person.history.homeStreet'); // undefined
obj.hash('person.animal.pet.needNoseAntEater'); // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment