Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Last active March 22, 2019 11:24
Show Gist options
  • Save indatawetrust/1eb9960308a382a1bd301f51abda8dbc to your computer and use it in GitHub Desktop.
Save indatawetrust/1eb9960308a382a1bd301f51abda8dbc to your computer and use it in GitHub Desktop.
Array.prototype.uniq = function(key) {
return key
? this.map(e => e[key])
.map((e, i, final) => final.indexOf(e) === i && i)
.filter(e => this[e])
.map(e => this[e])
: [...new Set(this)];
}
Array.prototype.asyncMap = async function(func) {
const data = []
for (let item of this) {
data.push(await func(item))
}
return data
}
Array.prototype._concat = function() {
return this.reduce((prev, next) => prev.concat(next), [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment