Get total, max and min number from an array of numbers:
var numArr = [17,18,19,20,53,65,78,99,12,35];
var total=0;
numArr.forEach(function(d,k){
total += d //or total = totl + d
});
console.log(total); // 416
Finding max:
Math.max(...numArr);
OR
console.log(Math.max.apply(null, numArr));
Finding minimum:
Math.min(...numArr)
console.log(Math.min(...numArr));
or
Math.min.apply(null, numArr);
console.log(Math.min.apply(null, numArr));
var numArr = [17,18,19,20,53,65,78,99,12,35];
var total=0;
numArr.forEach(function(d,k){
total += d //or total = totl + d
});
console.log(total); // 416
Finding max:
Math.max(...numArr);
OR
console.log(Math.max.apply(null, numArr));
Finding minimum:
Math.min(...numArr)
console.log(Math.min(...numArr));
or
Math.min.apply(null, numArr);
console.log(Math.min.apply(null, numArr));
Comments
Post a Comment