Filter and Map Lab
Overview
In this lab, we'll use our filter
and map
functions to write functions that properly query our data and return new arrays.
Instructions
Be sure to run the tests to get a feel for the types of problems this lab is asking you to solve.
You'll be writing four functions:
driversWithRevenueOver
- This function takes an array ofdriver
JavaScript objects as the first argument and a string calledrevenue
as the second argument. It returns an array ofdriver
objects that have arevenue
attribute that's greater than the passed-inrevenue
argument.driverNamesWithRevenueOver()
- This function works the same way asdriversWithRevenueOver()
. The difference is that it returns an array of strings representing the name of each driver who has a revenue greater than the specified amount. For example,driverNamesWithRevenueOver(drivers, 2000)
will return['Sammy']
, asSammy
is the name of the matchingdriver
object with a revenue greater than2000
.exactMatch()
- This function takes an array ofdriver
objects as the first argument and a JavaScript object that specifies an attribute and corresponding value. For example,exactMatch(drivers, { revenue: 3000 })
will return all drivers whoserevenue
attribute equals3000
, andexactMatch(drivers, { name: 'Bob' })
will return all drivers whosename
attribute equalsBob
.exactMatchToList()
- This function works the same way as theexactMatch()
function, except that instead of returning an array ofdriver
objects, it returns an array of strings with each element in the array corresponding to the matching driver's name. For example,exactMatchToList(drivers, { revenue: 2000 })
will return['Sammy']
, asSammy
is the name of the matchingdriver
object.
Does this need an update?
Please open a GitHub issue or pull-reqeust. Provide a detailed description that explains the issue you have found or the change you are proposing. Then "@" mention your instructor on the issue or pull-reqeust, and send them a link via Connect.
Resources
View Filter and Map Lab on Learn.co and start learning to code for free.
PHRG Filter and Map Lab