Skip to content

Instantly share code, notes, and snippets.

@ESeufert
Created May 2, 2014 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ESeufert/5a25e31abbd7ca076d92 to your computer and use it in GitHub Desktop.
Save ESeufert/5a25e31abbd7ca076d92 to your computer and use it in GitHub Desktop.
function cloneData(data) {
//create a "deep copy" of the objects within the metrics array
//ensures that objects are not copied by reference
var metrics = [];
for (var i = 0; i < data.length; i++) {
metrics.push(cloneMetric(data[i]));
}
return metrics;
}
function cloneMetric(metric) {
var tmp = [];
tmp[0] = metric[0];
for (var k = 1; k < metric.length; k++) {
tmp.push( jQuery.extend(true, {}, metric[k]) );
}
return tmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment