Use binary-search-bound instead

Find the index of the first element greater than x in a sorted array

npm install upper-bound
9 downloads in the last week
110 downloads in the last month


Finds the first item in a sorted array greater than a given value.


Use binary-search-bounds instead


First install using npm:

npm install upper-bound

Then use as follows:

var ub = require("upper-bound")

console.log(ub([0, 1, 1, 1, 2], 0))    // Prints 1
console.log(ub([0, 1, 1, 1, 2], 1))    // Prints 4

require("upper-bound")(array, value[, compare, lo, hi])

Uses a binary search to find the first item which is greater than value in array.

  • array a sorted list of items
  • value the item to find
  • compare a comparison function (optional)
  • lo a lower bound to search on (optional)
  • hi an upper bound on the range to search on (optional)


(c) 2013 Mikola Lysenko. MIT License

npm loves you