HTML and CSS Reference
In-Depth Information
filter , since the method must keep track of the current count. This method will pass the
following to our function for each member in the array:
1. The current result.
2. The value of the current member of the array.
3. The index that member has in the array (starting at 0).
4. The array itself.
//
The methods filter , map and reduce are not unique to JavaScript. These are im-
portant operators for dealing with data sets in many languages, and were pop-
ularised by Google's map/reduce algorithm for indexing web pages.
http://static.googleusercontent.com/external_content/untrusted_dlcp/re-
search.google.com/en//archive/mapreduce-osdi04.pdf
In order to see this working, execute the following:
[1,2,3,4,5].reduce(function(total, currentValue, index, array) {
console.log('Current value is ' + currentValue);
console.log('Total is ' + total);
return total += currentValue;
});
This will print the following:
Current value is 2
Total is 1
Current value is 3
Total is 3
Current value is 4
 
Search WWH ::




Custom Search