Skip to content

Instantly share code, notes, and snippets.

@katemihalikova
Last active April 28, 2017 21:39
Show Gist options
  • Save katemihalikova/677c9a405e6bc0d8e86ac2610ce8b8ce to your computer and use it in GitHub Desktop.
Save katemihalikova/677c9a405e6bc0d8e86ac2610ce8b8ce to your computer and use it in GitHub Desktop.
Shuffle images for pexeso
function zamichat(selektor) {
let obrazky = [];
document.querySelectorAll(selektor).forEach(elem => obrazky.push(elem.src));
zamichatPole(obrazky);
document.querySelectorAll(selektor).forEach((elem, i) => elem.src = obrazky[i]);
}
function zamichatPole(pole) {
for (let odkud = pole.length - 1; odkud >= 0; odkud--) {
let kam = Math.floor(Math.random() * (odkud + 1));
[pole[odkud], pole[kam]] = [pole[kam], pole[odkud]];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment