/    Sign up×
Community /Pin to ProfileBookmark

Duplicate checking in an Array. please help

I am new to JavaScript programming. Could any one help me in solving this problem? My problem is to find the duplicate value in the array.

I have a single dimension array with the following data stored on it.

[COLOR=Magenta]a[0] = 1~1~10[/COLOR]
a[1] = 1~2~11
a[2] = 1~3~15
a[3] = 1~4~19
a[4] = 0~5~10
[COLOR=Magenta]a[5] = 1~6~10[/COLOR]

Here in my case a[0] and a[5] is duplicate because i am using 1 or 0 for active and deactivate purpose a[4] is deactivate value so we can ignore the 10 in this. so in my case 10 is repeated twice on a[0]and a[5] not a[4], so its duplicate value. can any one help me to solve this.
Thanks you.
wowrang.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jalarieAug 03.2006 — Does this help?
<i>
</i>a=new Array();
a[0] = '1~1~10';
a[1] = '1~2~11';
a[2] = '1~3~15';
a[3] = '1~4~19';
a[4] = '0~5~10';
a[5] = '1~6~10';
for (i=0; i&lt;a.length; i++) {
v1=a[i];
v2=v1.split(/~/);
if (v2[0] == 1) { // active
for (j=i+1; j&lt;a.length; j++) {
w1=a[j];
w2=w1.split(/~/);
if (w2[0] == 1) { // active
if (w2[2] == v2[2]) { // a match
alert('Item '+j+' matches item '+i+'.');
}
}
}
}
}
Copy linkTweet thisAlerts:
@Mr_JAug 03.2006 — Done something similar

[code=php]<script type="text/javascript">

a=new Array()

a[0] = "1~1~10"
a[1] = "1~2~11"
a[2] = "1~3~15"
a[3] = "1~4~19"
a[4] = "0~5~10"
a[5] = "1~6~10"

str=""

for(var i=0;i<a.length;i++){

temp1=a[i].split("~")

for(var j=i+1;j<a.length;j++){

temp2=a[j].split("~")

if(j!=i&&temp1[0]==temp2[0]&&temp1[2]==temp2[2]){

str+="Index "+i+" = "+temp1+"n"
str+="Index "+j+" = "+temp2+"n"

}


}

}

alert(str)

</script>

[/code]
Copy linkTweet thisAlerts:
@wowrangauthorAug 04.2006 — Mr J & jalarie thanks alot for your time. problem resolved. Thanks.
×

Success!

Help @wowrang spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...