Create a gist now

Instantly share code, notes, and snippets.

_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