Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

ticket draw

draw(winnerCount) {
    const tickets = ["rasel", "rabina", "santo", "rajib", "billal"];
    const winnerIndexes = new Array(winnerCount);
    let winnerIndex = 0;
   if(tickets.length){
    while (winnerIndex < winnerCount) {
      const ticketIndex = Math.floor(Math.random() * tickets.length);
      if (!winnerIndexes.includes(ticketIndex)) {
        winnerIndexes[winnerIndex++] = ticketIndex;
        continue;
      }
      console.log("hi")
    }

    const winners = winnerIndexes.map((winner) => tickets[winner]);
    return winners;
   }
  }
 
PREVIOUS NEXT
Tagged: #ticket #draw
ADD COMMENT
Topic
Name
8+6 =