• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checking for unique values in an array

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Slime does not pay. Always keep your tiny ad dry.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic