Hello there,

I'm struggling here [1]. I can't see why the function to remove duplicates
is not working. The script is included below, the link is the function in a
live TW.

I've spent ages looking a the this one and testing. I can't see the flaw in
the logic.

ALex
[1] https://dl.dropbox.com/u/1316865/OMM/Omm/DirectorExerimental.html

arrUnique
========
<script>
//Adds new uniqueArr values to temp array (see-
http://www.developersnippets.com/2008/10/30/remove-duplicates-from-array-using-javascript/
)

function uniqueArr(a) {
    temp = new Array();
        for(i=0;i<a.length;i++){
            if(!contains(temp, a[i])){
            temp.length+=1;
                temp[temp.length-1]=a[i];
            }
        }
return temp;
}

//Will check for the Uniqueness
function contains(a, e) {
    for(j=0;j<a.length;j++)
    if(a[j]==e)return true;
return false;
}

var out=[],all=[];
tids=['Q1','Q2','Q3','Q4','Q5','Q6','Q7','Q8','Q9','Q10','Q11','Q12','Q13','Q14','Q15','Q16','Q17','Q18','Q19','Q20','Q21','Q22','Q23','Q24'];
for (var i=0; i<tids.length; i++) {
        var t=tids[i].title;
    var score=DataTiddler.getData(Questions[i],"score");
    var val=store.getValue(tids[i],"primary");
    var val1=store.getValue(tids[i],"secondary");
    var filter="[tag["+val.readBracketedList().join("]][tag[")+"]]";
    var filter1="[tag["+val1.readBracketedList().join("]][tag[")+"]]";
    var
list=store.filterTiddlers(filter).map(function(t){return""+t.title+""});
    var
list1=store.filterTiddlers(filter1).map(function(t){return""+t.title+""});
    var list2 =(list.concat(list1));
        if (score <= 2) {
        all.push(list2);
        }
}
out = uniqueArr(all);
return out.join(",");
</script>

Alex
[1]

2009/11/26 Alex Hough <[email protected]>

> thanks for that Mark
>
>
> "In some cases you might increment the value each time you insert the item,
> thus automatically tracking the number of occurrences of each item you are
> tracking"
>
> this is a good idea: It could lead to the output being like a 'tag cloud'
>
>
> Alex
>
>
>
>
>
>
>> The hash
>> automatically "compacts" out all unique items, which you can then list
>> by iterating over the map or hash.
>>
>> Mark
>>
>> On Nov 25, 1:32 pm, Alex Hough <[email protected]> wrote:
>> > Thanks Mark,
>> >
>> > I'll try this. I'm going a few steps back to get a few steps forward
>> here.
>> >
>> > Could you provide a link the the 'hash compact method' ?
>> >
>> > ALex
>> >
>> > 2009/11/25 Mark S. <[email protected]>
>> >
>> >
>> >
>> > > Thought about using the hash compact method the other day ... can't
>> > > remember why I didn't pursue it.
>> >
>> > > Anyways, you're not using the object generated by the funtion. Try
>> > > changing this:
>> >
>> > >  eliminateDuplicates(arrToClean);
>> > >  out.push(clean);
>> >
>> > > to this:
>> >
>> > >  out = eliminateDuplicates(arrToClean);
>> >
>> > > Mark
>> >
>> > > On Nov 25, 3:51 am, Alex Hough <[email protected]> wrote:
>> > > > I've found a way to eliminate duplicates from an array [1] and
>> applied it
>> > > to
>> > > > my code. I am not familiar enough with functions to know why it does
>> not
>> > > > work, but think that it is a simple solution.
>> >
>> > > > the script is below
>> >
>> > > > Alex
>> >
>> > > > [1]
>> > >http://stackoverflow.com/questions/840781/easiest-way-to-find-duplica.
>> ..
>> >
>> > > > <script>
>> >
>> > > > function eliminateDuplicates(arr) {
>> > > >   var i,
>> > > >       len=arr.length,
>> > > >       clean=[],
>> > > >       obj={};
>> >
>> > > >   for (i=0;i<len;i++) {
>> > > >     obj[arr[i]]=0;
>> > > >   }
>> > > >   for (i in obj) {
>> > > >     clean.push(i);
>> > > >   }
>> > > >   return clean;
>> >
>> > > > }
>> >
>> > > > var arrToClean=[];
>> > > > var out=[];
>> > > > tids=['Q1','Q2','Q3','Q4','Q5','Q6'];
>> > > > for (var i=0; i<tids.length; i++) {
>> > > >         var t=tids[i].title;
>> > > >     var score=DataTiddler.getData(tids[i],"score");
>> > > >     var val=store.getValue(tids[i],"primary");
>> > > >     var val1=store.getValue(tids[i],"secondary");
>> > > >     var filter="[tag["+val.readBracketedList().join("]][tag[")+"]]";
>> > > >     var
>> filter1="[tag["+val1.readBracketedList().join("]][tag[")+"]]";
>> > > >     var
>> >
>> > >
>> list=store.filterTiddlers(filter).map(function(t){return"[["+t.title+"]]"});
>> > > >     var
>> >
>> > >
>> list1=store.filterTiddlers(filter1).map(function(t){return"[["+t.title+"]]"});
>> >
>> > > > arrToClean.push(list.concat(list1));
>> >
>> > > > }
>> >
>> > > > eliminateDuplicates (arrToClean);
>> > > > out.push(clean);
>> > > > return out.join("\n");
>> > > > </script>
>> >
>> > > --
>> >
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "TiddlyWiki" group.
>> > > To post to this group, send email to [email protected].
>> > > To unsubscribe from this group, send email to
>> > > [email protected]<tiddlywiki%[email protected]>
>> <tiddlywiki%[email protected]<tiddlywiki%[email protected]>
>> >
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/tiddlywiki?hl=en.
>> >
>> > --http://www.multiurl.com/g/64
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "TiddlyWiki" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<tiddlywiki%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/tiddlywiki?hl=en.
>>
>>
>>
>
>
> --
> http://www.multiurl.com/g/64
>
>


-- 
http://www.multiurl.com/g/64

--

You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.


Reply via email to