MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / nearestValue

Function nearestValue

packages/backend/src/tailwind/conversionTables.ts:7–11  ·  view source on GitHub ↗
(goal: number, array: Array<number>)

Source from the content-addressed store, hash-verified

5import { rgbTo6hex } from "../common/color";
6
7export 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
14export const nearestValueWithThreshold = (

Callers 4

gradientDirectionFunction · 0.90
nearestOpacityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected