// trouvez 🚀
const getRandomArray = (length) => {
return Array.from({ length }, () => Math.floor(Math.random() * 5));
};
getRandomArray(5); //
const arr = getRandomArray(5);
// give max
const max = Math.max( 🚀 ); //
// give max with reduce
const maxWithReduce = arr.reduce( 🚀 );
// give min and max with reduce
const minMaxWithReduce = arr.reduce(
🚀 ,
{ min: Infinity, max: -Infinity }
);
//use destructuring to get min and max
const { 🚀 } = minMaxWithReduce;
console.log(min, maximum);
// give ocurrences of numbers in array
const occurrences = arr.reduce((acc, val) => {
🚀 );
console.log(occurrences);
Exemple d'affichage :