Create Using Map With Arrays



Over at Maple Mountain, the guys and gals on the development team need help with a problem. They received some name data from the customer terminal which they’d like to use to customize greetings for each of their passengers, but alas, the array turns out to consist of many subarrays where the first and last names of each passenger are split up. This makes it a “huge” hassle to change all of their pre-existing code, which was written to look for just one string in one cell of the array they were expecting. They should really have known to check what sort of data they were receiving first, right? Heh. Those guys.

Anyway, to correct their mistake, they’ve asked you to write them a function that will unite the first and last names of each passenger into one string, and then map that function across their entire array of data. Furthermore, they’d like the function expression built only as a parameter within the map function. (“NO CHEATING WITH VARIABLES!” – The Dev Team).

As an example, if Jason was riding the roller coaster (and when isn’t he), your goal would be to change his cell from ["Jason", "Millhouse"] to just "Jason Millhouse". Notice that an array goes in to the function you will build, but a string comes out.

The existing array is provided for you below. Remember to store your array of new data, and name that variable modifiedNames.

var passengers = [ ["Thomas", "Meeks"], 
                   ["Gregg", "Pollack"], 
                   ["Christine", "Wong"], 
                   ["Dan", "McGaw"] ];