Jak znaleźć najmniejszą liczbę w tablicy JS
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)
static int SmallestNumberin(int[] numbers){
int smallestNumber = numbers[0];
for (int i = 1; i < numbers.Length +1; i++)
{
if(numbers[i] < smallestNumber){
smallestNumber = numbers[i];
}
}
return smallestNumber;
}
function sumTwoSmallestNumbers(numbers) {
numbers = numbers.sort((a, b) => {
return a - b; });
}; //this will turn the numbers list into the 2 lowest numbers
Array.min = function( array ){
return Math.min.apply( Math, array );
};
var arr = ['cats', 'giants', 'daughters', 'ice'];
var min = Math.min(...arr.map(({ length }) => length));
console.log(min);
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);