Skip to content

Instantly share code, notes, and snippets.

@AlexeyNik
Last active July 29, 2020 07:27
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 AlexeyNik/8b02a0c8353b126497a66e492c0800de to your computer and use it in GitHub Desktop.
Save AlexeyNik/8b02a0c8353b126497a66e492c0800de to your computer and use it in GitHub Desktop.
Минимальное
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