Not only that, but if the array contains objects, the toString()  
method on the Object prototype will cause all but one object to be  
removed from the array, because all objects without an overridden  
toString() method report "[object]".

On Aug 30, 2007, at 5:50 PM, Tom Gregory wrote:

> On Aug 30, 2007, at 5:52 PM, Mislav Marohnić wrote:
>
>> On 8/31/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>> also, for generating unique arrays:
>>
>> function uniqueArray( array ){
>> var uniqueHash = {}, unique=[], i;
>> for( i=array.length; i--; ){
>> if( !uniqueHash[ a[i] ]){
>> unique.push( array[i] );
>> uniqueHash[ a[i] ] = true;
>> }
>> }
>> return unique;
>> }
>
> Although I expect this to be faster (linear time), this produces  
> incorrect results for certain arrays due to the implicit toString 
> (). Arrays of DOM elements might not be properly uniq-ed, for  
> example. The same is true for the following array (which uniq()  
> handles properly):
>
> var a = [true, "true"];
>
> console.log( a.uniq() );
> // [true, "true"]
>
> console.log( uniqueArray(a) );
> // [true]
>
>
>
> TAG
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to