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

108
Views
4 numbers max variance calculation

I have an array of four numbers, something like [597103978, 564784412, 590236070, 170889704] and I need to make sure that the variance is no more than 10%, for example for the array above, the check must fail because of the number 170889704.

Can someone suggest me a good method how to do that is Javascript?

Thanks in advance!

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

0

I would do it using Array.every

const arr = [597103978, 564784412, 590236070, 170889704];

const variance = (n, m) => {
  return Math.abs( (n - m) / n );
};

const isLessThanTenPercent = (n) => {
  return ( n < 0.1 );
};

const arrayIsGood = arr.every((n, i) => {

  // m is the next element after n
  const m = arr[i+1];
  if (Number.isInteger(m)) {
    const v = variance(n, m);
    return isLessThanTenPercent(v);
  } else {
    // if m is not an integer, we're at the last element
    return true;
  }

});

console.log({arrayIsGood});

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!