Created
February 19, 2017 21:57
-
-
Save Noitidart/a1f52c4e33616fa164a50e6bfa2d00f9 to your computer and use it in GitHub Desktop.
_js-useful.js - Useful little snippets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isBetween(num, range) { | |
// returns true if number is within range | |
// range is array [lowernum, highernum] | |
let [min, max] = range; | |
let rez = num >= min && num <= max; | |
// console.log('isBetween:', rez, num, range.join('-')); | |
return rez; | |
} | |
function isOverlap(range1, range2) { | |
// depends on isBetween | |
// range1 and range2 are [lowernum, highernum] arrays | |
// returns true if range1 and range2 share any common point (inclusive - meaning if range 1 ends at point 8 and range 2 starts at point 8, it is considered overlapping) | |
let [min1, max1] = range1; | |
let rez = isBetween(min1, range2) || isBetween(max1, range2); | |
// console.log('isOverlap:', rez, range1.join('-'), range2.join('-')); | |
return rez; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment