From 2dcb45a9f75f0a2ca563337449c918c921470b30 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sun, 19 Jun 2016 15:34:07 +0300 Subject: [PATCH] You have compound assignment in JS, no need to swap Some code review --- index.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 4c1a7ca..18bb3ad 100644 --- a/index.js +++ b/index.js @@ -11,15 +11,11 @@ const images = [ //TODO `https://upload.wikimedia.org/wikipedia/en/2/28/Arik_Marshall.jpg`, `http://www4.pictures.zimbio.com/gi/Morrissey+In+Concert+VNKNUCnyrAil.jpg` ]; -const swap = (array, i, j) => { - let tmp = array[i]; - array[i] = array[j]; - array[j] = tmp; -}; + const shuffle = array => { for (let i = array.length; i; i--) { let j = Math.floor(Math.random() * i); - swap(array, i - 1, j); + [array[j], array[i - 1] = [array[i - 1], array[j]]; } }; const startGame = numOfPlayers => { @@ -100,4 +96,4 @@ $(() => { $(`#cont`).empty(); $(`.choose-num-of-players`).show(); }); -}); \ No newline at end of file +});