Created
March 19, 2018 14:24
-
-
Save nicolaisueper/52863997e9a6eb3d49108cd0c318e479 to your computer and use it in GitHub Desktop.
smoosh and smooshMap JavaScript 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.smoosh = function () { | |
function smooshInternal(array) { | |
var smooshed = []; | |
for (var i = 0; i < array.length; i++) { | |
if (array[i] instanceof Array) { | |
smooshed.push.apply(smooshed, smooshInternal(array[i])); | |
} else { | |
smooshed.push(array[i]); | |
} | |
} | |
return smooshed; | |
} | |
return smooshInternal(this); | |
}; | |
Array.prototype.smooshMap = function (projectionFunction) { | |
return this.smoosh().map(projectionFunction); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment