Created
June 18, 2015 14:07
-
-
Save fredericksilva/52646a942062f25d7c22 to your computer and use it in GitHub Desktop.
Chaining the Array map and filter methods Arquivo 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exchanges = [ | |
[ | |
{ symbol: "XFX", price: 240.22, volume: 23422 }, | |
{ symbol: "TNZ", price: 332.19, volume: 234 } | |
], | |
[ | |
{ symbol: "JXJ", price: 120.22, volume: 5323 }, | |
{ symbol: "NYN", price: 88.47, volume: 98275 } | |
] | |
]; | |
Array.prototype.concatAll = function() { | |
var results = []; | |
this.forEach(function(subArray) { | |
subArray.forEach(function(item) { | |
results.push(item); | |
}); | |
}); | |
return results; | |
}; | |
var stocks = exchanges.concatAll(); | |
exchanges.concatAll().forEach(function(stock) { | |
console.log(JSON.stringify(stock)); | |
}); | |
/* | |
exchanges.forEach(function(exchange) { | |
exchange.forEach(function(stock) { | |
console.log(JSON.stringify(stock)); | |
}); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment