Created
September 21, 2015 09:19
-
-
Save rahulkumar-aws/2ac98e913941295f7191 to your computer and use it in GitHub Desktop.
Javascript flatMap implementation
This file contains 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
Array.prototype.flatMap = function(lambda) { | |
return Array.prototype.concat.apply([], this.map(lambda)); | |
}; | |
Example | |
[0, 1, 2, 3, 4, 5].flatMap(function(x) { | |
return [x, x + 1]; | |
}); | |
// [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment