Home > front end >  How can you check if an array contains a duplicate? JavaScript
How can you check if an array contains a duplicate? JavaScript

Time:02-10

Start with an empty array, and add the numbers 1 - 10 RANDOMLY only allowing a number to be repeated once. eg: when generated, the array would contain two 1's, two 2's, and so on. [1, 1, 2, 2,... 9, 9, 10, 10]

arr = []

getrandomNum() => {
  let randomNum = Math.floor(Math.random() * 10) - 1;}
  arr.push(randomNum)

This example allows more than two of the same number to be generated and I'm not sure what the logic would be not allow more than two 1's or two 5's and so on.

The end result will be apart of a bigger picture; a numbers games like the one on Countdown https://en.wikipedia.org/wiki/Countdown_(game_show)

CodePudding user response:

  •  Tags:  
  • Related