1 Replies - 787 Views - Last Post: 30 October 2019 - 12:49 PM

#1 Tildm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-October 19

Random number not to come twice

Posted 30 October 2019 - 12:43 PM

I want to load randomly two images from an array, but I want to avoid to be loaded the same images, here is what I tryed to do:

  
       this.seenCastles = new Set(this.state.castles.map(j => j.id));

       const isUnique = this.seenCastles.has(id);
           if (!isUnique) {
           
           castles.push({id, image, place, votes: 0 });
           this.seenCastles.add(id);
      } else {
          console.log(id)
    }
  }



here is the whole code, uploaded to github:
My link

Is This A Good Question/Topic? 0
  • +

Replies To: Random number not to come twice

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,796
  • Joined: 12-June 08

Re: Random number not to come twice

Posted 30 October 2019 - 12:49 PM

What's the question?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1