-1

For example, if I want to check if any number between 6 and 9 is between 8 and 16, how would I do this? In this case it would be true because 8 and 9 are both between 8 and 16.

j08691
  • 204,283
  • 31
  • 260
  • 272
Jess
  • 1
  • 1

2 Answers2

0
function rangeOverlaps(rangeA, rangeB) {
    return rangeA[0]<=rangeB[1] && rangeB[0]<=rangeA[1]
}
console.log(rangeOverlaps([8,16],[6,9])) //true
console.log(rangeOverlaps([8,16],[8,8])) //true
console.log(rangeOverlaps([8,16],[4,7])) //false

Explanation: What's the most efficient way to test if two ranges overlap?

CoderMuffin
  • 519
  • 1
  • 10
  • 21
0

Something like this

    function trying(x,y,z,w){
    return ((x >= z && x <= w) && (y >= z 
    && y <= w));
    }
Milford P
  • 48
  • 6