These examples demo how "map" would be used. It is a great utility function in oo and functional logic.

The "mapping function" converts an element into a new element.

Thus, over a collection, all "old" elements are converted to new elements.

We assume we are given an "array" for each example below which is a MyArray object.

Map Measurements to New Unit (e.g. feet to inches)
//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]
Map Customers to Customer Names
//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", ...]
Map Teams to the Team Coaches
//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