Skip to content

Commit

Permalink
Update arraysPractice.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermcginnis committed May 25, 2015
1 parent de08bf7 commit d081177
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions arraysPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,116 @@ for(var i = 0; i < num2; i++){
*/

//Code Here




//NEXT PROBLEM




var devMountainEmployees = [];

var tyler = {
name: 'Tyler',
position: 'Lead Instructor/Engineer',
spiritAnimal: 'Honey Badger'
};

var cahlan = {
name: 'Cahlan',
position: 'CEO',
spiritAnimal: 'butterfly'
};

var ryan = {
name: 'Ryan',
position: 'Marketing',
spiritAnimal: 'fox'
};

var colt = {
name: 'Colt',
position: 'Everything really',
spiritAnimal: 'Young Male Horse'
}

/*Above you're given an empty array with four objects. Fill the devMountainEmployees
array with those four objects. After that console.log the length of the Array and make
sure that it's equal to 4. */

//Code Here

/*Now let's say Cahlan has a mental breakdown and has to take a leave of absense to 'find himself'.
Loop through your devMountainEmployees until you find cahlan, then remove him from the array.*/

//Code Here




//NEXT PROBLEM




/*Now we're going to combine what we've learned today (objects) with what we learned
yesterday (arrays). Yeah, take a deep breathe. You're ready for this, promise.
Let's think back to our itunes example (tylermcginnis.com/itunes).
Notice that when you type in an artist name, iTunes gives us back a LOT of data.
What they're really giving us is an Array full of Objects. It probably looks something
like this. */

var data = [
{
artist: 'shakira',
album: 'hips don\'t lie',
tracks: 16,
},
{
artist: 'shakira',
album: 'mariposa',
tracks: 12,
},
{
artist: 'shakira',
album: 'greatest hits',
tracks: 19
}
];



/*A very clean way to pass around large LISTS (arrays) of COLLECTIONS (objects)
of Data is to have an Array full of objects. */

//Create an empty array called users.

//Code Here

/*Now add three user objects to your users array. Each user object should contain the
following properties. name, email, password, username.*/

//include this as one of the objects in your array.
var user1 = {
name: 'Tyler McGinnis',
email: '[email protected]',
password: 'iLoveJavaScript',
username: 'infiniateLoop'
}

//Your Code Here

/*Now you have a very common data structure. Twitter is a good use case.
It's easy to imagine that your followers list on Twitter is an Array full or objects
and those objects contain properties about the specific person you follow.*/

/*Now let's say that Tyler decided to delete his account. Loop through your array of
objects until you find Tyler's account (use [email protected] to find him).
Once you find the particular indice he's located in, delete him from the array.*/

//Code Here

//The activity we just did is very much how data works in 'the real world'.

0 comments on commit d081177

Please sign in to comment.