1007 0 0 0
Last Updated : 2025-04-28 22:42:20
If you need to use the prototype to add new general methods to any general protoype or construct functions such as Object, Array, String .. etc, here are few examples
Array.prototype.getMinMaxVals = function() {
var t0 = performance.now()
const min= Math.min(...this);
const max= Math.max(...this);
/*
const min = this.reduce((prevValue, currentValue)=>{
return (currentValue < prevValue) ? currentValue : prevValue ;
})
const max = this.reduce((prevValue2, currentValue2)=>{
return (currentValue2 > prevValue2) ? currentValue2 : prevValue2 ;
}) */
var t1 = performance.now()
console.log("This process took " + (t1 - t0) + " milliseconds.")
return {
min: min,
max: max,
}
/*
return {
min: Math.min(...this),
max: Math.max(...this),
}
*/
}
const grades = [10, 7, 25, 2, 105, 0.7, 300, 2150, 410];
console.log(grades.getMinMaxVals());
//Bets choice is to use the Math.min and Math.max?