Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
masonbarge

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Sorry for the delay. Okay, on the sortWords() function, I think I was thinking it would be called by map(), but didn't use it that way. I'll get this added to the errata page. Sorry about the confusion.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...