//array is numbers in this case [1, 2, 3] //say we want to convert the input (in "feet") to "inches" //thus we "map" each value from feet to inches (multiply by 12) let convertFeetToInchesFct = (measurementInFeet) => 12 * measurementInFeet let valuesInInches = array.map(convertFeetToInchesFct) //valuesInInches should be [12, 24, 36]
//array is "Customer" objects in this case //say we want to get all of our customer names //thus we "map" each customer to their name let customerToNameFct = (aCustomer) => aCustomer.getFirstName() + ' ' + aCustomer.getLastName() let customerNames = array.map(customerToNameFct) //customerNames should be something like: //["Suni Lee", "Gable Steveson", ...]
//Say we want to get a listing of all coaches in the league //array is "Team" objects in this case //say we want a list of all "coaches" in the league //thus we "map" each team to its coach let teamToCoachFct = (aTeam) => aTeam.getCoach() let coaches = array.map(teamToCoachFct) //coaches should now be an array of "Coach" objects