Last active
April 28, 2017 21:39
-
-
Save katemihalikova/677c9a405e6bc0d8e86ac2610ce8b8ce to your computer and use it in GitHub Desktop.
Shuffle images for pexeso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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