Sorted Index For Descending Order

Using the Lodash sortedIndex() function to check the sorted insertion index for arrays in descending order.

JavaScript

var data = [ 5, 3, 2, 1 ],
    value = 4,
    index;

index = _.sortedIndex( data, value, function( i ) {
    return -i;    
});

data.splice( index, 0, value );

console.log( data );