Contact List - Search for friends


#1

Hello
I was wondering why we are making two functions and using two for in loops for this challenge. Doesn't this make more sense?

var list = function(name){
        for (var foo in friends){
            if(foo === name){
                console.log(friends[foo]);
        };
    };
};
list('steve');


#2

We use two functions because they each have a unique purpose. list() is a simple untilty to list the primary keys of an object (in this case, friends). We are given this function first so we get some practice with for..in.

The search() function is a little more elaborate given a more specific purpose, but it builds upon what we learned writing the list() function. Combining the two functions doesn't make a lot of sense given their differences.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.