Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

closestTo

import { closestTo } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030?
const dateToCompare = new Date(2015, 8, 6)
const result = closestTo(dateToCompare, [
  new Date(2000, 0, 1),
  new Date(2030, 0, 1)
])
//=> Tue Jan 01 2030 00:00:00
function closestTo<DateType extends Date>(dateToCompare: DateType | number | string, dates: Array<DateType | number | string>): DateType | undefined;
§
closestTo<DateType extends Date>(dateToCompare: DateType | number | string, dates: Array<DateType | number | string>): DateType | undefined
[src]

§Type Parameters

§
DateType extends Date
[src]

§Parameters

§
dateToCompare: DateType | number | string
[src]
  • The date to compare with
§
dates: Array<DateType | number | string>
[src]
  • The array to search

§Return Type

§
DateType | undefined
[src]

The date from the array closest to the given date or undefined if no valid value is given