import { closestIndexTo } from "https://deno.land/x/date_fns@v2.12.0/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
// 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