I want to run a function that each time randomly chooses an element from an array that wasn\'t chosen before. And if all elements were chosen, I want to reset the used eleme
Here's a solution that's pretty short. It uses randojs.com to simplify the randomness and make it more readable, though I kinda threw a wrench in the "easy to read" part by making it super short. If you're having trouble understanding, here are some resources that will help explain: declaring variables on one line, the ternary operator, different ways to declare a function, the pop() method, and randojs
You can actually make the JavaScript one line if you want by just removing the line break, but I chose to make it two for the sake of clarity and shorter lines.
var arr = ["one", "two", "three", "four"], shuffled = randoSequence(arr),
uniqueRandom = () => (shuffled.length ? shuffled : shuffled = randoSequence(arr)).pop().value;
NOTE: this code won't work if you forget to import randojs with the script tag, so make sure to paste that in the head of your HTML document if you want to use this code.