Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Created February 19, 2017 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Noitidart/a1f52c4e33616fa164a50e6bfa2d00f9 to your computer and use it in GitHub Desktop.
Save Noitidart/a1f52c4e33616fa164a50e6bfa2d00f9 to your computer and use it in GitHub Desktop.
_js-useful.js - Useful little snippets.
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