I had a rather general question here regarding this problem insofar as the proper way to think of Object ‘enumeration’ in Javascript.
From the Docs, if I have the terminology correct, ‘source’ has only one ‘property’, so it is easy to directly instantiate ‘Object’ to get at ‘key/value’ pairs. However, ‘collection’ has multiple ‘properties’. Knowing this ahead of time, it is easy enough to then adjust and pull these ‘key/value’ pairs from the respective [index].
In this problem, further, this configuration is already sort of ‘made known’ to us ahead of time. I guess what I am wondering is what if you didn’t know the number of properties/levels the incoming object had ? Or what if each individual property of the object also had a second layer contained within it ?
The ‘Object’ structure itself doesn’t seem to have a .depth or .length type function to be able to determine the size of the object you are dealing with.
What’s the right way to think/go about this ?
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = Object.entries(collection);
// Only change code below this line
console.log(Object.entries(collection));
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: