Minimalna liczba JavaScript w tablicy
const min = arr => Math.min(...arr);
Batman
const min = arr => Math.min(...arr);
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
// Getting min value
var arr = [5,1,9,5,7];
var min = Math.min(...arr);
console.log(min); // 1
// Getting max value
var arr = [5,1,9,5,7];
var min = Math.max(...arr);
console.log(min); // 9
var numbers = [1, 2, 3, 4];
Math.max(...numbers) // 4
Math.min(...numbers) // 1
public class ArrayMin {
public static void main(String[] args) {
double[] numbers = new double[4];
numbers[0] = 1.7;
numbers[1] = 1.9;
numbers[2] = 5.7;
numbers[3] = 6;
double min = numbers[0];
for (int i = 0; i < numbers.length; i++) {
if(numbers[i] < min) {
min = numbers[i];
}
System.out.println(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);