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

255
Views
Destructuring within an argument list

Let's say I have the following function:

function get_scaled_coordinates(x, y, scale) {
    return [x*scale, y*scale];
}

Is it possible if I have a single variable with [x,y] to pass to the function. Perhaps something similar to this, conceptually speaking:

let point = [1,1];
get_scaled_coordinates(**point, scale);
// instead of having to do get_scaled_coordinates(point[0], point[1], scale)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could take an array as target for destructuring.

function get_scaled_coordinates([x, y], scale) {
    return [x * scale, y * scale];
}

If you like to use higher dimensions, you could map the array with new values.

function get_scaled_coordinates(coordinates, scale) {
    return coordinates.map(v => v * scale);
}
about 4 years ago · Juan Pablo Isaza Report

0

Perhaps something similar to this, conceptually speaking:

get_scaled_coordinates(**point, scale);

You seem to be looking for spread syntax in the function call:

get_scaled_coordinates(...point, scale);

No need to change the function, making it accept an array.

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!