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

112
Views
How to create an objectBuilder function

Any help would be appreciated.

Create a function objectBuilder that takes in a number and returns an object whose keys are 0 up to number and the values are that same number multiplied by 5.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try using for loop

console.log(objectBuilder(5))

// declare function
function objectBuilder(number) {
  // declare empty object
  const obj = {}
  // loop from 0 to number
  for (let i = 0; i <= number; i += 1) {
    // set key of i to value of i * 5
    obj[i] = i * 5
  }
  // return object
  return obj
}

about 4 years ago · Juan Pablo Isaza Report

0

You can do it like this:

I am sorry that I am actually doing this @evolutionxbox

You can create JavaScript class that will do it for you:

class objectBuilder {
    constructor(number){
        for(let i=0;i<=number;++i) this[i]=i*5
    }
}
//to initiate it create new instance of a class
const newObj = new objectBuilder(5)

console.log(newObj)

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!