Skip to content

Instantly share code, notes, and snippets.

@nola
Last active January 3, 2016 05:59
Show Gist options
  • Select an option

  • Save nola/8419770 to your computer and use it in GitHub Desktop.

Select an option

Save nola/8419770 to your computer and use it in GitHub Desktop.

Revisions

  1. nola revised this gist Jan 14, 2014. 1 changed file with 0 additions and 10 deletions.
    10 changes: 0 additions & 10 deletions address2.js
    Original file line number Diff line number Diff line change
    @@ -34,15 +34,5 @@ var search = function(name) {
    }
    };

    // adding new additions to our objects
    function add(firstName, lastName, phoneNumber, email){
    contacts[contacts.length]={ //interesting, insert at that last point in the array. array starts at zero so length is perfect
    firstName: firstName,
    lastName: lastName,
    phoneNumber: phoneNumber,
    email: email
    }
    }

    list(friends);
    search("Steve");
  2. nola revised this gist Jan 14, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion address2.js
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,6 @@ function add(firstName, lastName, phoneNumber, email){
    phoneNumber: phoneNumber,
    email: email
    }

    }

    list(friends);
  3. nola revised this gist Jan 14, 2014. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions address2.js
    Original file line number Diff line number Diff line change
    @@ -34,5 +34,16 @@ var search = function(name) {
    }
    };

    // adding new additions to our objects
    function add(firstName, lastName, phoneNumber, email){
    contacts[contacts.length]={ //interesting, insert at that last point in the array. array starts at zero so length is perfect
    firstName: firstName,
    lastName: lastName,
    phoneNumber: phoneNumber,
    email: email
    }

    }

    list(friends);
    search("Steve");
  4. nola revised this gist Jan 14, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion address2.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    var friends = {};

    //add people to it
    friends.bill = { //observe this notation
    friends.bill = { //observe this declaration as bill is an object of friends
    firstName: "Bill",
    lastName: "Gates",
    number: "(206) 555-5555",
  5. nola created this gist Jan 14, 2014.
    38 changes: 38 additions & 0 deletions address2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    //create an object
    var friends = {};

    //add people to it
    friends.bill = { //observe this notation
    firstName: "Bill",
    lastName: "Gates",
    number: "(206) 555-5555",
    address: ['One Microsoft Way','Redmond','WA','98052']
    };

    //add another
    friends.steve = {
    firstName: "Steve",
    lastName: "Jobs",
    number: "(408) 555-5555",
    address: ['1 Infinite Loop','Cupertino','CA','95014']
    };

    //log out all contents of the object
    var list = function(obj) {
    for(var prop in obj) {
    console.log(prop);
    }
    };

    //search for "steve"
    var search = function(name) {
    for(var prop in friends) {
    if(friends[prop].firstName === name) {
    console.log(friends[prop]);
    return friends[prop];
    }
    }
    };

    list(friends);
    search("Steve");