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:
Created | Nov 6, 2013 |
Published | Nov 6, 2013 |
Warriors Trained | 13186 |
Total Skips | 343 |
Total Code Submissions | 38579 |
Total Times Completed | 10512 |
JavaScript Completions | 10477 |
Total Stars | 82 |
% of votes with a positive feedback rating | 90% of 438 |
Total "Very Satisfied" Votes | 366 |
Total "Somewhat Satisfied" Votes | 58 |
Total "Not Satisfied" Votes | 14 |