Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

closest-to

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

closest-to

A function that, when given a target number and an array of numbers, will return the array value closest to the target.

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

closest-to

closest-to finds the closest value to a given target in a sorted array of numbers

Build status

Browser support

Install

npm install closest-to

Usage

require('closest-to')(needle, haystack, [returnIndex])
require('closest-to/nd')(needle, haystack, [returnIndex])
closest(10, [1, 3, 5, 7, 9])
> 9
closest(10, [1, 3, 5, 7, 9], true)
> 4
ndclosest([1, 2], [[1, 1], [2, 3], [3, 4]])
> [1, 1]

ndclosest([1, 2], [[1, 1], [2, 3], [3, 4]], true)
> 0

Benchmarks

closest-to@1.0.1 x 116,156 ops/sec ±1.02% (85 runs sampled)
closest-to@2.0.0 x 860,497 ops/sec ±1.09% (83 runs sampled)

License

MIT

Keywords

FAQs

Package last updated on 20 Jan 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc