Skip to content

Instantly share code, notes, and snippets.

@Jks15063
Created April 15, 2015 20:31
Show Gist options
  • Save Jks15063/4302e8c2364f00cf7763 to your computer and use it in GitHub Desktop.
Save Jks15063/4302e8c2364f00cf7763 to your computer and use it in GitHub Desktop.
var flatSteps = [];
flatMetrics.forEach(function(flatMetric) {
flatMetric.forEach(function(step) {
flatSteps.push(step);
});
});
===========================================================
var flatSteps = flatMetrics.concatMap(function(metric) {
return metric.steps;
});
Array.prototype.concat = function() {
var results = [];
this.forEach(function(subArray) {
results.push.apply(results, subArray);
});
return results;
}
Array.prototype.concatMap = function(projectionFunction) {
return this.map(function(item) {
return projectionFunction(item);
})
.concat();
}
==========================================
LoDash version :)
_(flatMetrics)
.map(function(metric) {
return metric.steps;
})
.flatten();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment