JavaScript trouve le plus petit nombre dans un tableau
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)
var arr = ["aaaa", "aa", "aa", "aaaaa", "a", "aaaaaaaa"];
console.log(
arr.reduce((a, b) => a.length <= b.length ? a : b)
)
//Not using Math.min:
const min = function(numbers) {
let smallestNum = numbers[0];
for(let i = 1; i < numbers.length; i++) {
if(numbers[i] < smallestNum) {
smallestNum = numbers[i];
}
}
return smallestNum;
};
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);