fix calculateColor function

Fix sorting co2Scale to not be in place, change finding scaleIndex to be equal to closestNum (not greater than).
pull/1121/head
Konrad Rydzak 2 years ago committed by GitHub
parent 207136a537
commit 11d58c0f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -65,11 +65,11 @@ function calculateColor(value) {
let co2Scale = [0, 150, 600, 750, 800];
let colors = ['#2AA364', '#F5EB4D', '#9E4229', '#381D02', '#381D02'];
let closestNum = co2Scale.sort((a, b) => {
let closestNum = co2Scale.slice().sort((a, b) => {
return Math.abs(a - value) - Math.abs(b - value);
})[0];
console.log(value + ' is closest to ' + closestNum);
let num = (element) => element > closestNum;
let num = (element) => element === closestNum;
let scaleIndex = co2Scale.findIndex(num);
let closestColor = colors[scaleIndex];

Loading…
Cancel
Save