0

Given this code:

random: function() {
  return Math.floor(Math.random() * 100 + 1)
}

let result = []

result.push(random()) // it doesn't matter if this integer is pushed again in the next line
[...Array(10)].forEach((_, i) => result.push(random())) // all of these have to be unique

How can I make sure that no duplicates are pushed to result except possibly the first while maintaining the length of the array at 11?

t56k
  • 6,769
  • 9
  • 52
  • 115

0 Answers0