Opened 12 years ago
Closed 5 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 )
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)
Change History (11)
Changed 11 years ago by
Attachment: | unique.patch added |
---|
comment:1 Changed 11 years ago by
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. |
comment:2 Changed 11 years ago by
Milestone: | tbd → 1.5 |
---|
Marking as 1.5 to get rid of TBD's from the list of 1.4 bugs.
comment:3 Changed 11 years ago by
Cc: | Eugene Lazutkin added |
---|---|
Component: | Core → Dojox |
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:5 Changed 11 years ago by
Milestone: | 1.5 → 1.6 |
---|
comment:6 Changed 10 years ago by
Milestone: | 1.6 → 1.7 |
---|---|
Owner: | changed from dante to Eugene Lazutkin |
did we still want to do this?
comment:7 Changed 10 years ago by
Milestone: | 1.7 → 1.8 |
---|
comment:8 Changed 9 years ago by
Milestone: | 1.8 → 2.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 8 years ago by
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 5 years ago by
Milestone: | 2.0 → 1.11 |
---|---|
Resolution: | → patchwelcome |
Status: | new → closed |
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
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)