Skip to content

Instantly share code, notes, and snippets.

@nicolaisueper
Created March 19, 2018 14:24
Show Gist options
  • Save nicolaisueper/52863997e9a6eb3d49108cd0c318e479 to your computer and use it in GitHub Desktop.
Save nicolaisueper/52863997e9a6eb3d49108cd0c318e479 to your computer and use it in GitHub Desktop.
smoosh and smooshMap JavaScript implementation
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