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

207
Views
Check if there is a value in the array which has more than 10 difference with other values

I want to check if there is a value in the array which has more than 10 difference with other values:

console.log(check());

function check() {
    const array = [21, 21, 10];  
    return array.some((val, i, arr) => val > arr[0] + 10);
}

The above array should return true because there is at least one value in the array which has more than 10 difference, But as you see it returns false!!

How can I do this?

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

0

You could take the max and min value and check the difference.

function check(array) {
    return Math.max(...array) - Math.min(...array) > 10;
}

console.log(check([21, 21, 10]));

about 4 years ago · Juan Pablo Isaza Report

0

You are checking if any of the array items are bigger than the first item + 10, which is not true.

You can check every element with the minimum element though:

console.log(check());

function check() {
    const array = [21, 21, 10];
    const min = Math.min(...array);
    return array.some(val => val > min + 10);
}

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!