Closed wraithgar closed 9 years ago
I have no idea what this function should actually be called. The three ways I know of to get values into an array are push, unshift, and splice. This technically splices under the hook but when I wrote it it was replacing a push()
then .sort()
chain.
Looks like this functionality should be ported instead? http://underscorejs.org/#sortedIndex
You'll notice sortedIndexOf
is just a function inside of this new module but it could totally be separated out, and maybe should be?
In thinking about this, I don't think we should call it sorted-push
because "push" implies pushing it onto a stack. What do you think about sorted-insert
?
I definitely like sorted-insert
better than sorted-push
for the reason @HenrikJoreteg stated.
My other suggestion would be sorted-add
, similar to http://ampersandjs.com/docs/#ampersand-collection-add
I think "insert" implies position more strongly than "add".
On Thu, Jan 29, 2015 at 1:10 PM, Drew Fyock notifications@github.com wrote:
I definitely like
sorted-insert
better thansorted-push
for the reason @HenrikJoreteg stated.My other suggestion would be
sorted-add
, similar to http://ampersandjs.com/docs/#ampersand-collection-addReply to this email directly or view it on GitHub: https://github.com/AmpersandJS/amp/pull/79#issuecomment-72104710
Ok renamed to sorted-insert, and also made it actually use sorted-index which I somehow forgot to check in before.
I think this is ready for merge and initial publish. @AmpersandJS/core-team feedback appreciated.
inserting in-person +1 i just got from @wraithgar :)
:shipit:
woot! shipped.
This allows you to push items into an already sorted array and maintain the sort order without having to manually resort the whole array.