Giter Site home page Giter Site logo

michielab / lab-javascript-lodash-exercises Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ironhack-labs/lab-javascript-advanced-collection-methods

0.0 2.0 0.0 9 KB

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

JavaScript 98.94% HTML 1.06%

lab-javascript-lodash-exercises's Introduction

JS | Lodash Exercises

These exercises will help you to practice and discover some of the most useful functions Lodash provides.

To solve them, please refer to the formal Lodash documentation and take a look at the files in the starter code in this repository.

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.

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.

๐Ÿ’ก Hint: Look at the Lodash Array methods. Use _.times if you need to repeat an action.

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.

๐Ÿ’ก Hint: Look at the Lodash Array methods.

  1. 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.

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.

๐Ÿ’ก Hint: Look at the Lodash Array methods. Use _.times if you need to repeat an action.

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);

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

Lodash is a great tool for retrieving information. But first, 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

Lodash could help you, specially when starting to code, to think in a more functional manner. It is also a good tool to avoid repetition and speed up coding time. Through these exercises you got familiar with the Lodash documentation and some of the over a 100 functions it provides.

Extra Resources

lab-javascript-lodash-exercises's People

Contributors

fontcuberta avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.