diff --git a/underscore.object.selectors.js b/underscore.object.selectors.js index cd548e6..6d8cc2c 100644 --- a/underscore.object.selectors.js +++ b/underscore.object.selectors.js @@ -109,6 +109,24 @@ keysFromPath: keysFromPath, + //Returns the property with the greatest numeric value in an object along with it's key in an array [key,value]. + maxVal: function(obj){ + + return Object.keys(obj).reduce(function(currentVal, key){ + return obj[key] > currentVal[1] ? [key,obj[key]] : currentVal + }, ["key",-Infinity]); + + }, + + //Returns the property with the least numeric value in an object along with it's key in an array [key,value]. + minVal: function(obj){ + + return Object.keys(obj).reduce(function(currentVal, key){ + return currentVal[1] > obj[key] ? [key,obj[key]] : currentVal + }, ["key",Infinity]); + + }, + pickWhen: function(obj, pred) { var copy = {};