Skip to content

Instantly share code, notes, and snippets.

@fredericksilva
Created June 18, 2015 14:07
Show Gist options
  • Save fredericksilva/52646a942062f25d7c22 to your computer and use it in GitHub Desktop.
Save fredericksilva/52646a942062f25d7c22 to your computer and use it in GitHub Desktop.
Chaining the Array map and filter methods Arquivo 3
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