Set polyfill with a "has" method more efficient than O(n)

Peter Michaux petermichaux at gmail.com
Fri Mar 30 17:29:47 PDT 2012


On Thu, Mar 29, 2012 at 10:20 PM, Brendan Eich <brendan at mozilla.org> wrote:
> Peter Michaux wrote:
>>
>> I've worked on a generic Set polyfill. It is quite a simple task to
>> build one but determining if an object is in the set is O(n) with the
>> following "has" method.
>>
>>     Set.prototype.has = function(element) {
>>         for (var i = 0, ilen = this._elements.length; i<  ilen; i++) {
>>             if (element === this._elements[i]) {
>
>
> You need Object.is here, not ===, per
>
> http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets
>
> Object.is spec:
>
> http://wiki.ecmascript.org/doku.php?id=harmony:egal

Thanks for mentioning this.

What is the license on the "is" function implementation shown in the
wiki? I'd like to include it in a file that is 2-clause BSD licensed.
I see the wiki itself is under the CC non-commercial license which
seems incompatible.

Peter


More information about the es-discuss mailing list