(goal: number, array: Array<number>)
| 5 | import { rgbTo6hex } from "../common/color"; |
| 6 | |
| 7 | export const nearestValue = (goal: number, array: Array<number>): number => { |
| 8 | return array.reduce((prev, curr) => { |
| 9 | return Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev; |
| 10 | }); |
| 11 | }; |
| 12 | |
| 13 | // New function to get nearest value only if it's within acceptable threshold |
| 14 | export const nearestValueWithThreshold = ( |
no outgoing calls
no test coverage detected