Jump to content
Larry Ullman's Book Forums

Need Help With Map()


Recommended Posts

I'm in Chapter 7 pp 250-253 (words.js) and don't get something.

 

The heart of the js is the line in where the map and sort methods are chained in the sortWords(max) function definition.

 

var sorted = words.map (function(value) {return value.toLowerCase();}).sort();

 

What I don't understand is how or why the parameter "value" in the anonymous function gets its argument. Obviously it receives the value of each item in the array but I can't figure out why.

 

While I'm at it, I can't understand why sortWords(max) has the parameter "max". Is this just a feature that wasn't used but got left in?

Link to comment
Share on other sites

Good questions. The parameter "value" could be named anything, but it just goes to receive the single value that the map() function will pass to the anonymous function with each iteration.

 

As for sortWord(), let me take a look at that and see what I was thinking.

Link to comment
Share on other sites

  • 1 month later...
 Share

×
×
  • Create New...