Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!