Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Created March 19, 2015 22:12
Show Gist options
  • Save ultim8k/d1ef5042684001452f37 to your computer and use it in GitHub Desktop.
Save ultim8k/d1ef5042684001452f37 to your computer and use it in GitHub Desktop.
Merge cwllections
var ar = [{date:'2015-01-01', data:15}, {date:'2015-02-01', data:18}, {date:'2015-02-05', data:10}, {date:'2015-02-06', data:25}];
var br = [{date:'2015-01-01', v:3}, {date:'2015-02-01', v:1}, {date:'2015-02-09', v:20}];
var merged = [];
for(var i=0;i<ar.length;i++){
var check = 0;
for(var j=0;j<br.length;j++){
if(ar[i].date === br[j].date) {
check = 1;
merged.push({date: ar[i].date, data: ar[i].data, v: br[j].v});
continue;
}
}
if (check !== 1) {
merged.push({date: ar[i].date, data: ar[i].data, v: 0});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment