Opened 10 years ago

Closed 4 years ago

#9205 closed enhancement (patchwelcome)

[patch/cla] Addition of array.unique to Dojo's array functions.

Reported by: Lightflowmark Owned by: Eugene Lazutkin
Priority: high Milestone: 1.11
Component: Dojox Version: 1.3.0
Keywords: array unique Cc: Eugene Lazutkin
Blocked By: Blocking:

Description (last modified by bill)

I think a function to return the unique values of an array, analagous to array_unique in PHP, would be a useful addition to Dojo's excellent array additions. It's a function I find regularly useful in other languages (and have just found a need for it in Javascript), and was surprised not to find it in Dojo. Code like

thisModule.unique= function (/* Array */ mixedArray)
  {
    testArr = new Array();
    uniqueArray = new Array();
    dojo.forEach(mixedArray,function(i){
      if (!testArr[i]) // value not seen yet?
      {
        testArr[i] = true;
        uniqueArray.push(i);
      }
    });
    return(uniqueArray);
  }

would seem to do it in an efficient way (this isn't my code, btw - http://blog.archive.jpsykes.com/212/unique-array-filter-in-dojo/index.htm).

Attachments (1)

unique.patch (829 bytes) - added by dante 10 years ago.

Download all attachments as: .zip

Change History (11)

Changed 10 years ago by dante

Attachment: unique.patch added

comment:1 Changed 10 years ago by dante

Owner: changed from anonymous to Eugene Lazutkin
Summary: Addition of array.unique to Dojo's array functions.[patch/cla] Addition of array.unique to Dojo's array functions.

suggestions? seems d.l.f is the proper place for this overall, though the 'advanced' nature of d.l.f seems to make me want to make it support objects or something (unique members).

happy to add unit tests if you are ok w/ the function. otherwise close as wontfix. This likely doesn't belong in base, and there really isn't any other appropriate home for the functionality afaik.

if for whatever reason you would like it in base, i'm not sure I like the name 'unique' (as I'm proposing a more generic unique-id generator using the name dojo.unique)

comment:2 Changed 10 years ago by bill

Milestone: tbd1.5

Marking as 1.5 to get rid of TBD's from the list of 1.4 bugs.

comment:3 Changed 9 years ago by Eugene Lazutkin

Cc: Eugene Lazutkin added
Component: CoreDojox
Owner: changed from Eugene Lazutkin to dante

Looks good. Needs tests. I think it should go in a separate file: dojox/lang/functional/ext-array.js --- I have more filters to add, and this will be the first one.

comment:4 Changed 9 years ago by dante

see also #10768 for alt impl.

comment:5 Changed 9 years ago by dante

Milestone: 1.51.6

comment:6 Changed 8 years ago by dante

Milestone: 1.61.7
Owner: changed from dante to Eugene Lazutkin

did we still want to do this?

comment:7 Changed 8 years ago by Chris Mitchell

Milestone: 1.71.8

comment:8 Changed 7 years ago by Colin Snover

Milestone: 1.82.0

1.8 is frozen. Move all enhancements to next release. If you need an exemption from the freeze for this ticket, contact me immediately.

comment:9 Changed 6 years ago by bill

Description: modified (diff)

I think this will be handled in 2.0 if we base it on Lo-Dash, but otherwise perhaps worthwhile adding manually.

comment:10 Changed 4 years ago by dylan

Milestone: 2.01.11
Resolution: patchwelcome
Status: newclosed

At this point, I think the recommendation would be to just use an ES6 Set or WeakSet? if this capability is really needed. If someone wants to backport to 1.x, we'll consider a patch. In Dojo 2, we've added a shim for Map, but we haven't added Set, https://github.com/dojo/core/tree/master/src

Note: See TracTickets for help on using tickets.