JSFiddle - React, Tailwind, and code Playground
by CommandLineDesign
HTML
<ul id='log1'></ul><ul id='log2'></ul>
JavaScript
// ================================================ PriceRange ================================================ //
var PriceRange = function(name){
var _this = this;
var highest = 1;
var lowest = 0;
var difference = 0;
Object.defineProperty(this, 'name', {
value: name
})
Object.defineProperty(this, 'populate', {
set: function(valueArray){
Array.prototype.forEach.call(valueArray, function(item, index){
_this.update = item;
})
}
})
Object.defineProperty(this, 'update', {
set: function(value){
this.highest = value;
this.lowest = value;
}
})
Object.defineProperty(this, 'highest', {
set: function(value){
highest = value > highest ? value : highest
},
get: function(){
return highest;
}
})
Object.defineProperty(this, 'lowest', {
set: function(value){
if((value >= 1 && value < lowest) || !lowest){
lowest = value;
}
},
get: function(){
return lowest;
}
})
Object.defineProperty(this, 'range', {
get: function(){
if(this.highest === this.lowest){
return this.lowest;
}
return this.lowest + ' - ' + this.highest;
},
})
Object.defineProperty(this, 'difference', {
set: function(compareNode){
var highCompare = 0;
var lowCompare = 0;
if(compareNode.lowest){
lowCompare = Math.round(((compareNode.lowest - lowest)/compareNode.lowest)*100);
}
if(compareNode.highest){
highCompare = Math.round(((compareNode.highest - highest)/compareNode.highest)*100);
}
difference = highCompare > lowCompare ? highCompare : lowCompare;
return difference;
},
get: function(){
return difference;
...