Skip to content

Instantly share code, notes, and snippets.

@sbrl
Last active January 30, 2018 22:58
Show Gist options
  • Save sbrl/a725e32f14a3e4b94810 to your computer and use it in GitHub Desktop.
Save sbrl/a725e32f14a3e4b94810 to your computer and use it in GitHub Desktop.
[Range.js] A very simple range class. #es6 #module #microlibrary
/*******************************************************************************
******************************* ES6 Range Class *******************************
*******************************************************************************
* v0.2
*******************************************************************************
* A very simple range class.
*******************************************************************************
* https://gist.github.com/sbrl/a725e32f14a3e4b94810
* Author: Starbeamrainbowlabs <[email protected]>
*
* Changelog:
* v0.1 - 24th Jan 2015:
* Uploaded to GitHub Gist.
* v0.2
* Added ES6 module export syntax.
* Added range calculated parameter.
*/
/// [email protected] by Starbeamrainbowlabs ///
class Range
{
constructor(inMin, inMax) {
if(inMin > inMax)
throw new Error(`Min is bigger than max! (min: ${inMin}, max: ${inMax})`);
this.min = inMin;
this.max = inMax;
}
/**
* Calculates and returns the fistance between the maximum and the minimum.
* @return {number} The distance between the maximum and the minimum.
*/
get range()
{
return this.max - this.min;
}
}
export default Range;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment