Picking 2 random elements from array
do NOT use loops and comparisons. Instead
- shuffle the array
- take first two elements
It can be done using built-in functionality (slice and sort),
var n = 2
randomItems = array.sort(() => .5 - Math.random()).slice(0, n);