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

Brendan Eich brendan at mozilla.org
Fri Mar 30 17:42:49 PDT 2012


Don't worry about it -- I'll slap a PD declaration in there.

/be

Peter Michaux wrote:
> 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
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list