1.0.0 • Published 8 years ago

nearest-number v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

nearest-number

From a list of numbers, picks the one closest to a given target. Packaged as a Node.js module.

Installation

npm install nearest-number --save

Usage

const nearestNumber = require('nearest-number')

// Out of the numbers in the list, the number nearest to 13 is 10
nearestNumber([10, 25, 30], 13) // 10

// Returns the index of 10 in the array
nearestNumber([10, 25, 30], 13, {returnIndex: true}) // 0