Skip to content
Browse files

Merge pull request #1 from rwldrn/foreach

Adds forEach and corrects Array proto method titles to be accurate
  • Loading branch information...
2 parents 831f919 + 095d216 commit e564fd2d5b2285fc1008a38a6edca5bc5e60c718 Jonathan Blanchet committed Feb 16, 2012
Showing with 19 additions and 6 deletions.
  1. +19 −6 posts/Array_prototype_iteration.md
View
25 posts/Array_prototype_iteration.md
@@ -12,22 +12,35 @@ kind:
polyfillurls: [Array.prototype iteration methods polyfill](https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js)
ready: ready
-All those methods have been introduced in Javascript 1.6 or Javascript 1.8 (reduce and reduceRight) and available in most browsers and for those who don't, there are polyfills.
+All methods have been introduced in EcmaScript 5 & 5.1 and available in most browsers and for those who don't, there are polyfills.
-`Array.filter` creates a new array with all elements that pass the test implemented by the provided function.
+`Array.prototype.forEach` calls a callback function once for each item present in the array, in ascending order, returns `undefined`
-`Array.map` creates a new array with the results of calling a provided function on every element in this array.
+`Array.prototype.filter` creates a new array with all elements that pass the test implemented by the provided function.
-`Array.some` tests whether some element in the array passes the test implemented by the provided function.
+`Array.prototype.map` creates a new array with the results of calling a provided function on every element in this array.
-`Array.reduce` apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
+`Array.prototype.some` tests whether some element in the array passes the test implemented by the provided function.
-`Array.reduceRight` apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
+`Array.prototype.reduce` apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
+
+`Array.prototype.reduceRight` apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
function isBigEnough(element) { return (element >= 10); };
function sum(a, b) { return a + b; };
function flatten(a, b) { return a.concat(b); }
+
+ // forEach
+ [12, 5, 8, 130, 44].forEach(function( value ) {
+ console.log( value );
+ });
+ // 12
+ // 5
+ // 8
+ // 130
+ // 44
+
// Filter
[12, 5, 8, 130, 44].filter(isBigEnough); // [12, 130, 44]

0 comments on commit e564fd2

Please sign in to comment.
Something went wrong with that request. Please try again.