Giter Site home page Giter Site logo

js-advanced-functions-first-class-functions-lab's Introduction

JavaScript Advanced Functions: First-Class Functions Lab

Learning Goals

  • Assign functions to a variable.
  • Store functions in a data structure.
  • Write functions that return other functions.
  • Pass a function to another function.
  • Call a function returned by another function.

Introduction

Functions are a very important part of JavaScript, and you will use them all the time. Without functions, we wouldn't get anything done! In this lab, we'll take a look at how we can use functions as first-class objects to pass them around, store them in variables and data structures, and return them from other functions.

  • returnFirstTwoDrivers() — Declare a variable with const that is assigned an anonymous function. The assigned function should accept an array of drivers as an argument and return the first two drivers in the array.
  • returnLastTwoDrivers() — Declare a variable with const that is assigned an anonymous function. The assigned function should accept an array of drivers as an argument and return the last two drivers in the array.
  • selectingDrivers — This is an array containing two elements: the two functions that we previously defined (returnFirstTwoDrivers() and returnLastTwoDrivers()).
  • createFareMultiplier() — This is a higher-order function that takes in one argument, an integer, and returns a function that will multiply a fare for a ride accordingly. For example, if createFareMultiplier() receives an argument of 4, it will return a function that takes in a fare as an argument and quadruples the fare.
  • fareDoubler() — Declare a variable with const and assign a function returned by createFareMultiplier() to it. Invoke createFareMultiplier() in such a way that the new fareDoubler() function accepts a fare as its lone argument and doubles it.
  • fareTripler() — Declare a variable with const and assign a function returned by createFareMultiplier() to it. Invoke createFareMultiplier() in such a way that the new fareTripler() function accepts a fare as its lone argument and triples it.
  • selectDifferentDrivers() — This function takes two arguments, an array of drivers and either the returnFirstTwoDrivers() or returnLastTwoDrivers() function. Based on these two arguments, selectDifferentDrivers() will return either the first two drivers or the last two drivers.

Resources

js-advanced-functions-first-class-functions-lab's People

Contributors

drakeltheryuujin avatar gj avatar ihollander avatar jeffkatzy avatar lizbur10 avatar matt-development-work avatar maxwellbenton avatar oldgcdm avatar sgharms avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-advanced-functions-first-class-functions-lab's Issues

Link is broken

The JavaScript is Sexy: Higher-Order Functions link is broken and does not work.

SelectDifferentDrivers

This function and what it expects is really unclear. AND the tests pass if you just pass in one of the two functions (returnFirstTwoDrivers or returnLastTwoDrivers. And the suggested solution uses a function called whichDrivers, that isn't really clear, nor are the steps it would take to get there, and even the tech coach was stymied. Thanks for considering changing this for other students.
Screen Shot 2020-02-19 at 12 46 30 PM

This code passed. The tech coach had suggested just adding in one of the functions first, to see what the response would be, and that's how we figured out it passed.

if the goal is for us to use the selectingDrivers array, then you should give students more of a hint about that, or move it to just before this final function. Then you should change the solution code. And also, it would be great to see in the lab or lesson whether we can include the two functions just as an array, with brackets, as an argument (it doesn't, but showing us how to destructure here, or emphasizing the pattern of putting multiple functions into an array to pass in would be really helpful).

solution code to be changed to make things easier to understand
Screen Shot 2020-02-19 at 12 53 01 PM

screenshot of functions in bracketed array:
Screen Shot 2020-02-19 at 12 56 14 PM

Changing Function Name?

I feel like the #selectDifferentDrivers function should not be called that because we're selecting the same drivers. I actually wrote a function that enables us to nondestructively take the values in the array that are not values in the second argument, before I realized the opposite. (I know it's my fault for not reading the spec well, but I do think the function name is deceiving)

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.