Created
February 17, 2020 17:21
-
-
Save BrunoGiubilei/0a4d3b750544ec91dc95afc8c27fd41f to your computer and use it in GitHub Desktop.
min and max value prototype for array of object
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.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