JavaScript найдите наименьшее число в массиве
const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = Math.min(...arr)
console.log(min)
Yawning Yak
const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = Math.min(...arr)
console.log(min)
const array = [32, 22, 53, 92, 20, 34, 23, 11, 17];
let smallestNum = array[0];
let secondSmallestNum = 0;
for (let i = 1; i < array.length; i++) {
if (array[i] < smallestNum) {
secondSmallestNum = smallestNum;
smallestNum = array[i];
} else if (array[i] !== smallestNum && array[i] < secondSmallestNum) {
secondSmallestNum = array[i];
}
}
console.log(smallestNum);
console.log(secondSmallestNum);
Array.min = function( array ){
return Math.min.apply( Math, array );
};
const array = [320, 52, 532, 920, 20];
let smallestNum = array[0];
for (let i = 1; i < array.length; i++) {
if (array[i] < smallestNum) {
smallestNum = array[i];
}
}
console.log(smallestNum);
var arr = [5,1,9,5,7];
var smallest = arr[0];
for(var i=1; i<arr.length; i++){
if(arr[i] < smallest){
smallest = arr[i];
}
}
console.log(smallest);