Skip to content

philipwisner/lab-javascript-advanced-collection-methods

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

JS | Advanced Collection Methods Exercises

These exercises will help you to practice really usefull Javascript objects methods.

Requirements

Submission Instructions

Upon completion, run the following commands

$ git add .
$ git commit -m "done"
$ git push origin master

Navigate to your repo and create a Pull Request -from your master branch to the original repository master branch.

In the Pull request name, add your name and last names separated by a dash "-"

Deliverables

You'll receive two files under the lib/ folder. Keep them just how they are, they contain the data you will use in your exercise but they're not intended to be edited. Write your JavaScript in a new file and make sure you require it properly in the provided html file.

Iteration 1 - The Office

The Office picture

You work in a taxes office. Boring, right? And suddenly you discover you can use your extra time to learn how to code. An email arrives. Your bosses are sending a satisfaction survey. You decide to model the satisfaction of your coworkers.

As you have five departments with 10 people working in each department, your mission is to create a 5x10 array and fill it randomly with made up opinions to model the satisfaction survey results. Employees can be:

  • This is the best job ever
  • Satisfied.
  • At least I get paid.
  • I'm looking for another job.
  • I don't want to answer.
  1. Create an array that matches these opinions.
var opinions = [ "This is the best job ever",
                 "Satisfied",
                 "At least I get paid",
                 "I'm looking for another job",
                 "I don't want to answer"];
  1. Create a function that randomly picks up one of these items in the opinions array.

  2. Create a function that pushes the item into the array. You will need to repeat this procedure ten times to create an array of 10 opinions.

  3. Create another function that pushes the 10-items-array into another array. You will need to do this five times to create the five departments. At the end you will have something like the function below:

var employeeSatisfaction = function () {
  // Steps 2, 3 and 4 here
  return array;
};
  1. Show your result in the console.

Iteration 2 - Harry Potter's Birthdays

Navigating through Internet, we found a very messy array with the birthdays of Harry Potter's friends and enemies.

Harry Potter picture

Take a look at the harryPotter.js array. It is so messy, they can't even remember which date belongs to whom. But we know each date follows each character's name.

Let's organize Harry Potter Character's Birthdays. Unfortunately, Scourgify won't help us now, but Lodash could...

  1. Create a function that receives an array and returns an array of two dimensions. Each internal array should have the name of one character and his date of birthday.

  2. Now that we have our two-dimensions array, we notice that some of the birthdays are missing. But we found another array with birthdays from the book.

var moreBirthdays = ["Lily Evans", "30 January", "James Potter", "27 March",
                     "Dudley Dursley", "30 June", "Tom Riddle", "31 December"];
  1. Create a function that add this array above to the first one you manipulated with the same format. The function should return an array with all the birthdays in pairs.

Iteration 3 - The Password Problem

Yeah, yeah, to set a password is ALWAYS a big trauma. We will ask for a password to our users and we need to implement validation methods for this password.

eCard about Passwords

Different characters: create a function that receives a password and returns an error if every char in the password is not unique.

var goodPsswd = "1234567890";
var badPsswd = "1123456";
var noRepeatChar = function (password) {
 //your code goes here
};

noRepeatChar(goodPsswd);
noRepeatChar(badPsswd);

Only numbers: Create a function that receives a password and returns an error if the password has any character different than numbers.

var goodPsswd = "1234567890";
var badPsswd = "1a234567890";
var onlyNumbers = function () {
 //your code goes here
}
onlyNumbers(goodPsswd);
onlyNumbers(badPsswd);

Ten digits only: Create a function that trim the password and turns it into a 10 digits password. The function should keep the first 10 digits and discard the rest of them.

var goodPsswd = "1234567890";
var badPsswd = "12345678901234567890";
var trimPassword = function (password) {
 //your code goes here
}
trimPassword(badPsswd);

Iteration 4 - Abbey Road Studios

Abbey Road Studios opened in 1931. Through all these years, the amount of data they've been collecting is huge. We found a list of recordings made at Abbey Road Studios but we are not sure if it is actually an important place for music or if its fame is just a result of the hype created by The Beatles.

Abbey Road front door

Take a look at the data object located in the abbeyRoad.js file in your lib folder.

November looks like a good month: In the 30's, they use to gather information about the months when the recordings where made. Get the artist who recorded the most on November in Abbey Road.

var novemberArtists = function () {
  //your code
};
//Remember to execute the function to actually assing the value to the var.

Artists like to repeat: Get the artist who recorded the most times in Abbey Road.

var bestArtist = function () {
  //your code
};
//Remember to execute the function to actually assing the value to the var.

The Beatles and Abbey Road: When did the four of Liverpool recorded their last song in Abbey Road Studios?

var lastBeatlesSong = function () {
  //your code
};
//Remember to execute the function to actually assing the value to the var.

Sixties crazyness: The sixties were a crazy decade. Could you retrieve the last song it was recorded in Abbey Road Studios in the decade of 1960's?

var sixtiesSong = function () {
  //your code
};
//Remember to execute the function to actually assing the value to the var.

Summary

Collection methods are really usefull

Extra Resources

About

Some exercises to practice and discover some of the most useful functions Lodash provides

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.8%
  • HTML 1.2%