Created
April 15, 2015 20:31
-
-
Save Jks15063/4302e8c2364f00cf7763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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