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

228
Views
How can I create an array of sequential values through the input of the minimum and maximum values?

Let's say I want a logical sequence between 0 and 100 that has 1 number between them, so I set 0 in B1, 100 in B3 and add the formula in B2:

enter image description here

If I want with 9 numbers between them, I just change the cell where the 100 is:

enter image description here

Now I want to reproduce this using Google Apps Script so I don't have a circular dependency on my spreadsheet.

[[0],
[...],
[...],
[...],
[100]]

So far, I've tried this:

function between() {
  const min = 0;
  const max = 100;
  const total = 11;
  const seq = (min + max) / total;
  const lst = [[min]];
  let i = 1;
  while (i <= total-2) {
    lst.push([(seq*i).toFixed(2)])
    i++
  }
  lst.push([max])
  SpreadsheetApp.getActive().getSheetByName('data').getRange(1,2,lst.length,1).setValues(lst);
}

However, it doesn't generate the expected values. What should I adjust to get the correct result?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

By formula

=arrayformula(sequence(B3+1,1,B1*B3,(B2-B1))/B3)

or, according the the precision you need

=arrayformula((sequence(B3+1,1,B1*1000*B3,(B2-B1)*1000)/B3)/1000)

enter image description here

about 4 years ago · Santiago Gelvez Report

0

I'm not entirely sure what your calculation is doing in mathematical terms, but I tried to reconstruct your formula and came up with the following for loop (use this instead of your while loop):

for(let i = total - 2; i >= 1; i--) {
  let e = max + i * (min - max) / (total - 1);
  lst.push([e.toFixed(2)])
}
about 4 years ago · Santiago Gelvez 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!