// find mimimum value of array in javascript
// array reduce method
const arr = [49,2,71,5,38,96];
const min = arr.reduce((a, b) => Math.min(a, b));
console.log(min); // 2
// math.min apply method
const min_ = Math.min.apply(null, arr);
console.log(min_); // 2
// or math.min spread operator method
const min__ = Math.min(...arr);
console.log(min__); // 2
const arr = [10, 5, 0, 15, 30];
const min = Math.min.apply(null, arr);
const index = arr.indexOf(min); // get the index of the min in the array
console.log(index); // 2
var min = Math.min.apply(null, arr),
max = Math.max.apply(null, arr);
(function () {
const arr = [23, 65, 3, 19, 42, 74, 56, -42, 8, 88];
// const arr = [];
function findMinValue(arr) {
if (arr.length) {
let min = Infinity;
for (let num of arr) {
min = num < min ? num : min;
}
return min;
}
return 0; // or anything what you need
}
console.log(findMinValue(arr)); // => -42
})();
int min=0;
for(int i=0;i<array.length;i++)
{
if(array[i] < min)
min = array[i]
}
return min;