Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
function closestIndexTo
import { closestIndexTo } from "https://deno.land/x/date_fns@v2.0.0-alpha.34/index.js";

Examples

// Which date is closer to 6 September 2015? var dateToCompare = new Date(2015, 8, 6) var datesArray = [ new Date(2015, 0, 1), new Date(2016, 0, 1), new Date(2017, 0, 1) ] var result = closestIndexTo(dateToCompare, datesArray) //=> 1

Parameters

dirtyDateToCompare
  • the date to compare with
dirtyDatesArray
  • the array to search