0
Write a JavaScript program to find maximum and minimum value in an array
JavaScript
6 Antworten
+ 6
max=Math.max(...arr);
min=Math.min(...arr);
or..
max=Math.max.apply(null,arr);
min=Math.min.apply(null,arr);
several other ways
+ 4
I'll recommend you guys should learn ecmascript 6, it will save you the stress of typing shit like Max.prototype.aplly()..bla bla bla
+ 4
use the right set of words D'lite!
+ 2
Mind To Machine Forgive my words..
But let's tell ourselves the truth!
ES6 is a language that supports the notion: Write less, do same,period
+ 1
For max:
var arr=[1,2,3];
var mxval=0;
for(var i=0; i<arr.length; i++){
if(arr[i] >mxval){ mxval= arr[i];
console.log(mxval);}
}
//same reverse for min value