K. Gadd (2013-08-10T08:11:10.000Z)
domenic at domenicdenicola.com (2013-08-12T05:34:39.788Z)
I'm not sure I understand what use this container would have in common cases. You can simply sort an ordinary array and then binary search it. A 'SortedArray' primitive would be very strange in JS also since as soon as you modified the value at an index, either the array becomes unsorted or it has to be resorted and now the value you just wrote isn't there anymore, that is: ```js a[i] = 1; a[i] !== 1; ``` Which is pretty strange for a container. Normally a container like this would not allow those sorts of operations, which makes it somewhat less useful. If all you want is has/remove (I have no idea what 'set' would do in this case - is it just add?), why not use Set? Do you just need the ability to store duplicates? If so, I think a map of item->count might suffice, though I'm not sure precisely how easy that is to express in JS. It sounds like all you really need here is Array.binarySearch as a builtin (or JS polyfill) to implement the container you want, but it's also not clear why you want this container or what it would do for you. JS-based implementations can outperform native implementations in some cases; it depends. I think in this case a self-hosted implementation would end up faster, but only if it were specialized for the element type(s) in the array.