6 kyu

Extract Nested Object Reference

10,477 of 10,512maruf89

Description:

You are given a complex object that has many deeply nested variables. You don't want to go the usual if obj.property == null route. Create a prototype method that given a nested path, either return the value or undefined.

var obj = {
  person: {
    name: 'joe',
    history: {
      hometown: 'bratislava',
      bio: {
        funFact: 'I like fishing.'
      }
    }
  }
};

obj.hash('person.name'); // 'joe'
obj.hash('person.history.bio'); // { funFact: 'I like fishing.' }
obj.hash('person.history.homeStreet'); // undefined
obj.hash('person.animal.pet.needNoseAntEater'); // undefined
Refactoring

Similar Kata:

Stats:

CreatedNov 6, 2013
PublishedNov 6, 2013
Warriors Trained13186
Total Skips343
Total Code Submissions38579
Total Times Completed10512
JavaScript Completions10477
Total Stars82
% of votes with a positive feedback rating90% of 438
Total "Very Satisfied" Votes366
Total "Somewhat Satisfied" Votes58
Total "Not Satisfied" Votes14
Ad
Contributors
  • maruf89 Avatar
  • jhoffner Avatar
  • farhanaditya Avatar
Ad