Respuestas Ejercicio 51 (JS julio)

Comparte tu respuesta del ejercicio 51.

const max = (...arr) => Math.max(...arr)

const max = (...num) => Math.max(...num);

Respuesta:

const max = (...myArray) => myArray.reduce((accum, item) => accum > item ? accum : item, undefined);
const max = (...arr) => arr.reduce((a, b) => a > b ? a : b);
const max = (...arr) => {
  let max = arr[0]
  for (let i of arr){
    if(i > max) max=i
  }
  return max
}

Buenas noches esta es mi solución:

const max = (...arr)=>{
  let aux = arr[0];
  for(let i of arr){
    if(i>aux){
      aux=i
    }
  }
  return aux;
}
const max = (...arr) => Math.max(...arr);


console.log(max(1, 2, 3, 4))
console.log(max(63, 85, 39, 24, 3))
const max = (...arr) => arr.sort( (a, b) => a - b )[arr.length-1]
const max = (...arr) => arr.reduce((a, b) => (a > b ? a : b));
const max=(a,...b)=>{
  let aux=a;
  b.forEach(el=>el>=aux ? aux=el:aux=aux);
  return aux;
}
console.log(max(1, 2, 3, 4)) // 4
console.log(max(63, 85, 39, 24, 3)) // 85
1 me gusta
const max = (...arreglo) =>  {
  let max = arreglo[0]
  for (let i of arreglo){
    if(i > max) max=i
  }
  return max
}

Respuesta ejercicio 51:

// Ejercicio 51
const max = (first, ...arreglo) => {
  let maximo = first
  for(val of arreglo){
    if (maximo < val )
      maximo = val
  }
  return maximo
}
const max = (...num) => Math.max(...num)

Buenas tardes
Esta es mi respuesta

const max = (...arr) => arr.reduce((mayor,num)=>num>mayor?num:mayor,0)
// escribe tu solución acá
const max = (...nums) => {
  //console.log(nums)
  let theMax = nums[0];
  for (let i = 1; i <= nums.length; i += 1) {
    if (nums[i] > theMax) {
      theMax = nums[i];
    }
  }
  return theMax;
};

// código de prueba
console.log(max(1, 2, 3, 4)); // 4
console.log(max(63, 85, 39, 24, 3)); // 85

const max =(...nums)=>{
  let m=nums[0]
  for(let i of nums)
    if(i>m)
      m=i
  return m
}
const max = (...arr) => arr.reduce((a, b) => a > b ? a : b);
console.log(max([1, 2, 3, 4]))
console.log(max([63, 85, 39, 24, 3]))

const max = arr=>[…arr].reduce((aux1, aux2) => aux1 > aux2 ? aux1 : aux2);

const max = (...num) =>  num.reduce((max, curr) => (curr > max ? curr : max));