Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

nearest-date

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
547
41.34%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Build status js-standard-style

Installation

npm install nearest-date

Usage

var nearest = require('nearest-date')

var dates = [
  new Date('2012-12-12'),
  new Date('2024-12-12'),
  new Date('2022-12-12'),
  new Date('2016-12-12'),
  new Date('1980-12-12'),
]
var target = new Date('2016-12-27')

var index = nearest(dates, target)

console.log('Winner:', dates[index])

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

Keywords

distance

FAQs

Package last updated on 27 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts