Tighten specification for _.sortedIndex #563

merged 2 commits into from Apr 19, 2012
Commits on Apr 19, 2012
  1. Tighten specification for _.sortedIndex

    kevinoid committed Apr 19, 2012
    sortedIndex should specify that it returns the lowest index at which an
    item may be inserted to maintain sorted order, rather than any index
    which satisfies this property, in order to provide easier use
    maintaining a sorted list of unique elements.
    For example, with the previous specification, the following behavior is
    _.sortedIndex([10, 20, 30, 40], 30)
    => 3
    To accommodate this behavior users would have to check both array[si]
    and array[si-1] (when si > 0) before inserting to ensure uniqueness, or
    to examine the underscore.js implementation and rely on the
    implementation not changing.
    Note:  This specification change does not require any changes to the
    Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
  2. Add test for tightened sortedIndex specification

    kevinoid committed Apr 19, 2012
    Test that the lowest index, rather than any index, at which the element
    should be inserted to maintain sorted order is returned.
    Signed-off-by: Kevin Locke <kevin@kevinlocke.name>