Skip to content

Instantly share code, notes, and snippets.

@santiblanko
Created August 11, 2016 00:49
Show Gist options
  • Select an option

  • Save santiblanko/57069c95777a91e2cb612519cd6ad935 to your computer and use it in GitHub Desktop.

Select an option

Save santiblanko/57069c95777a91e2cb612519cd6ad935 to your computer and use it in GitHub Desktop.
var exchanges = [{
name:"NSYE",
stocks:[{
symbol:"LOL",
closes:[{
date: new Date(2014,11,24),
price:240.10
},{
date: new Date(2014,9,23),
price:241.10
},{
date: new Date(2014,8,22),
price:232.08
}]
}]
},{
name:"TNZ",
stocks:[{
symbol:"XFX",
closes:[{
date: new Date(2014,7,24),
price:521
},{
date: new Date(2014,5,23),
price:511
},{
date: new Date(2014,11,22),
price:519
}]
}]
}]
Array.prototype.concatAll = function(){
var results = [];
this.forEach(function(subarray){
subarray.forEach(function(item){
results.push(item);
});
});
return results;
};
var stocks = exchanges.map(function(o){
return o.stocks.map(function(e){
return e.closes.filter(function(aj){
return aj.date.getMonth() == 11
}).
map(function(s){
return {
price:s.price,
name: o.name
}
})
}).concatAll()
}).concatAll()
stocks.forEach(function(o){
console.log(o)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment