UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

10 lines (9 loc) 405 B
/** * Snaps a number to the nearest value in a custom set of values. * For example, snapToNearest(27, [0, 10, 30, 50]) returns 30. * @author @dailker * @param {number} n - The input number. * @param {number[]} values - The array of possible snap values. * @returns {number} The value from values closest to n. */ export declare function snapToNearest(n: number, values: number[]): number;