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

151
Vistas
Getting information from an Array with Strings and Integer Values as Strings by Size of Integer Values

Let's say you have an array that looks like this:

arr = ['Steve', '80000', 'Jen', '90000', 'Bob', '40000']

Where arr[0] and arr[2] are the names of employees and arr[1] and arr[3] are their salaries.

How would you go about writing a function that would return the name of the person with the largest salary?

In the example above we'd look for the function to return 'Jen' because she has the highest salary.

My initial thought would be to turn all the values in the array to integers using parseInt(), finding the maximum value and then pointing to the value of the index before that maximum value but am having trouble writing a correct solution for this. Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Chunk function

Object.defineProperty(Array.prototype, 'chunk', {value: function(n) {
    return Array.from(Array(Math.ceil(this.length/n)), (_,i)=>this.slice(i*n,i*n+n));
}});

Then we can easily process [Name, Salary] pairs like,

["a", "11", "b", "12", "c", "3"]
  .chunk(2)
  .sort((p1, p2) => parseInt(p2) - parseInt(p1))[0]
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