AmpersandJS / amp

a collection of individual JS utility modules
http://amp.ampersandjs.com
MIT License
130 stars 12 forks source link

add sorted-push and sorted-index #79

Closed wraithgar closed 9 years ago

wraithgar commented 9 years ago

This allows you to push items into an already sorted array and maintain the sort order without having to manually resort the whole array.

wraithgar commented 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.

wraithgar commented 9 years ago

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?

HenrikJoreteg commented 9 years ago

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?

fyockm commented 9 years ago

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

HenrikJoreteg commented 9 years ago

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 than sorted-push for the reason @HenrikJoreteg stated.

My other suggestion would be sorted-add, similar to http://ampersandjs.com/docs/#ampersand-collection-add

Reply to this email directly or view it on GitHub: https://github.com/AmpersandJS/amp/pull/79#issuecomment-72104710

wraithgar commented 9 years ago

Ok renamed to sorted-insert, and also made it actually use sorted-index which I somehow forgot to check in before.

HenrikJoreteg commented 9 years ago

I think this is ready for merge and initial publish. @AmpersandJS/core-team feedback appreciated.

HenrikJoreteg commented 9 years ago

inserting in-person +1 i just got from @wraithgar :)

fyockm commented 9 years ago

:shipit:

HenrikJoreteg commented 9 years ago

woot! shipped.