masonbarge Posted June 25, 2012 Share Posted June 25, 2012 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 More sharing options...
Larry Posted June 25, 2012 Share Posted June 25, 2012 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 More sharing options...
Larry Posted August 14, 2012 Share Posted August 14, 2012 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. Link to comment Share on other sites More sharing options...
Recommended Posts