Why does this count all objects twice?


#1

The following is supposed to list out the objects, which it does. The problem is that it iterates through them twice. I used the counter in this just to illustrate my point.

var address = [];
var friends = {};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 444-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']
};
var count = 0;

var list = function(friends) {
for (var prop in friends){
console.log(prop);
count++;
console.log(count);

}

};

list(friends);


#2

That is because the SCT (Submission Correctness Test) is also running the code to test it. We can ignore the extra output, just so long as we find ours to be as expected (will output first).