Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for unique values in an array

 
Madhusudhan GoturKaranam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an array which can have dynamic values..Don't know count..
I have to check for uniqueness in that array..

For Example, Array A1 = [1,2,3,3,1]

Here, '3' and '1' is repeated. I should for unique values and giving message if its repeated.

Pls help me..
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically you need to make a second array. Using the number of the firxt array, you add one too it. You need to loop through the whole array.

count[Array1[i]]

use the length property to check the number of elements.

No I am not going to code it!
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an idea - since you could use the numbers you going to store as array indexes.

so,

than you could use
for(var i in myArray){ ... }
to loop through array.
Or, you coul have 2 arrays - one for indexes and one for data
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic