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

closestIndexTo

import { closestIndexTo } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// Which date is closer to 6 September 2015?
const dateToCompare = new Date(2015, 8, 6)
const datesArray = [
  new Date(2015, 0, 1),
  new Date(2016, 0, 1),
  new Date(2017, 0, 1)
]
const result = closestIndexTo(dateToCompare, datesArray)
//=> 1
function closestIndexTo<DateType extends Date>(dateToCompare: DateType | number | string, dates: Array<DateType | number | string>): number | undefined;
§
closestIndexTo<DateType extends Date>(dateToCompare: DateType | number | string, dates: Array<DateType | number | string>): number | 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

§
number | undefined
[src]

An index of the date closest to the given date or undefined if no valid value is given