Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active January 26, 2023 10:45
Show Gist options
  • Select an option

  • Save luislobo14rap/5df99454b4da413f2154caeda9aceccf to your computer and use it in GitHub Desktop.

Select an option

Save luislobo14rap/5df99454b4da413f2154caeda9aceccf to your computer and use it in GitHub Desktop.
// between.js v1.1.1
function between(number, a, b, orEqual = false) {
const min = Math.min(a, b),
max = Math.max(a, b)
if (orEqual == true) {
return number >= min && number <= max
}
return number > min && number < max
}
Number.prototype.between = function(a, b, orEqual = false) {
return between(this, a, b, orEqual)
}
String.prototype.between = function(a, b, orEqual = false) {
return between(this, a, b, orEqual)
}
// between.min.js v1.1.1
function between(c,d,e,f=!1){let g=Math.min.apply(Math,[d,e]),h=Math.max.apply(Math,[d,e]);if(!0==f)return c>=g&&c<=h;return c>g&&c<h}Number.prototype.between=function(c,d,e=!1){return between(this,c,d,e)},String.prototype.between=function(c,d,e=!1){return between(this,c,d,e)};
@luislobo14rap

Copy link
Copy Markdown
Author

between(1,0,2) // true
1 its between 0 and 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment