(color)
| 48 | ]; |
| 49 | |
| 50 | function getClosestColorName(color) { |
| 51 | let diffs = []; |
| 52 | let keys = []; |
| 53 | for (const [key, value] of Object.entries(colorNames)) { |
| 54 | let colorDifference = getColorDifference(color, value); |
| 55 | if (colorDifference < 10) { |
| 56 | diffs.push(colorDifference); |
| 57 | keys.push(key); |
| 58 | } |
| 59 | } |
| 60 | if (diffs.length > 0) { |
| 61 | const minDiff = Math.min(...diffs); |
| 62 | const index = diffs.indexOf(minDiff); |
| 63 | const closestMatchingKey = keys[index]; |
| 64 | return capitalizeFirstLetter(closestMatchingKey); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function getRandomColorName() { |
| 69 | const existingColorNames = getAllColorNames(); |
no test coverage detected