Last active
July 29, 2020 07:27
-
-
Save AlexeyNik/8b02a0c8353b126497a66e492c0800de to your computer and use it in GitHub Desktop.
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 min = parseInt(this[this.length-1]), el; | |
for(var i=this.length-2; i>=0; i--){ | |
el = parseInt(this[i]); | |
if(el<min){ | |
min = el; | |
} | |
} | |
return min; | |
}; | |
Максимальное | |
Array.prototype.max = function(){ | |
var max = parseInt(this[this.length-1]), el; | |
for(var i=this.length-2; i>=0; i--){ | |
el = parseInt(this[i]); | |
if(el>max){ | |
max = el; | |
} | |
} | |
return max; | |
}; | |
Округление всех элементов массива | |
Array.prototype.toFixed = function(num){ | |
for(var i = 0; i < this.length; i++){ | |
this[i] = this[i].toFixed(num); | |
} | |
} | |
// использование: | |
var array = [1,3,5,-1,8,0]; | |
document.write(array.min());// -1 | |
document.write(array.max());// 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment