Skip to content

Instantly share code, notes, and snippets.

@BrunoGiubilei
Created February 17, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrunoGiubilei/0a4d3b750544ec91dc95afc8c27fd41f to your computer and use it in GitHub Desktop.
Save BrunoGiubilei/0a4d3b750544ec91dc95afc8c27fd41f to your computer and use it in GitHub Desktop.
min and max value prototype for array of object
Array.prototype.min = function() {
var self = this, p = arguments[0];
return self
.filter(f => p.zero === false ? f[p.prop] > 0 : f)
.map(m => m[p.prop])
.reduce((a, c) => {
return a = (a === undefined || c < a) ? c : a
});
}
Array.prototype.max = function() {
var self = this, p = arguments[0];
return self
.filter(f => f[p.prop] > 0)
.map(m => m[p.prop])
.reduce((a, c) => {
return a = (a === undefined || c > a) ? c : a
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment