Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
how does [len] became property of arr i.e. (Number(arr[len]) in the following code

i am unable to understand that how (Number(arr[len]) is composed. is [len] made the property of arr.

function arrayMax(arr) {
      var len = arr.length, max = -Infinity;
      while (len--) {
        if (Number(arr[len]) > max) {
          max = Number(arr[len]);
        }
      }
      return max;
    };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is probably some attempt at a super efficient way of getting the max value in a array.

len variable is badly named in all fairness. It should have been labeled index.

function arrayMax(arr) {
  var index = arr.length, max = -Infinity;
  while (index--) {
    if (Number(arr[index]) > max) {
      max = Number(arr[index]);
    }
  }
  return max;
};

And arr[index] gets the value at the specified index.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#access_an_array_item_by_its_index

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda