nearest-date
Given an array of dates, this module will find the date nearest to a given target date. Can be used to find the nearest number as well.
Installation
npm install nearest-date
Usage
var nearest = var dates = '2012-12-12' '2024-12-12' '2022-12-12' '2016-12-12' '1980-12-12'var target = '2016-12-27' var index = console
API
index = nearest(array[, target])
Finds the value in the array
nearest to the target
and returns the
index
of that value in the array
.
The target
defaults to Date.now()
.
Both the array
and the target
can be either Date
objects or
numbers.
License
MIT