40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
|
/*******************************************************************************
|
||
|
******************************* ES6 Range Class *******************************
|
||
|
*******************************************************************************
|
||
|
* v0.2
|
||
|
*******************************************************************************
|
||
|
* A very simple range class.
|
||
|
*******************************************************************************
|
||
|
* https://gist.github.com/sbrl/a725e32f14a3e4b94810
|
||
|
* Author: Starbeamrainbowlabs <bugs@starbeamrainbowlabs.com>
|
||
|
*
|
||
|
* Changelog:
|
||
|
* v0.1 - 24th Jan 2015:
|
||
|
* Uploaded to GitHub Gist.
|
||
|
* v0.2
|
||
|
* Added ES6 module export syntax.
|
||
|
* Added range calculated parameter.
|
||
|
*/
|
||
|
|
||
|
/// Range.js@v0.1 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;
|