documentcloud/underscore — Issue #484: array uniq unexpected results
Author: ajax333221
Created: 2012-02-20 05:37:59+00:00
State: open

var arr=[];
arr[2]=null;
arr[3]=null;
arr[8]=2;
arr[10]=2;
arr[11]=5;
arr[14]=5;
arr[16]=8;
arr[19]=8;
arr[26]=undefined;
arr[29]=undefined;
arr[33]="hi";

alert(_.uniq(arr,true)); //outputs to "2,5,8,,hi"

Problem?: The first 'null' value from the beginning was removed

Notes: This also happens if you start with 'undefined' values (and probably more)

--------------------------------------

Another bug:

If you change the 'null' values from my example with 'undefined' and remove the 'true' sorted parameter:

var arr=[];
arr[2]=undefined;
arr[3]=undefined;
arr[8]=2;
arr[10]=2;
arr[11]=5;
arr[14]=5;
arr[16]=8;
arr[19]=8;
arr[26]=undefined;
arr[29]=undefined;
arr[33]="hi";

alert(_.uniq(arr)); //outputs ",2,5,8,hi"

Problem?: The 'undefined' value from the middle was removed

Notes: The first 'undefined' value wasn't unchanged (this is good) unlike with the 'true' sorted parm