Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Comment on lines +68 to 70
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sorting logic finds the value with minimum absolute difference from the input value, but this doesn't guarantee it will be found in the original co2Scale array. If the input value is between two scale values, the closest might not exist in the original array, causing findIndex to return -1.

Copilot uses AI. Check for mistakes.
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];
Expand Down