LoginSignup
0
0

More than 3 years have passed since last update.

フィッシャー・イェーツのシャッフル

Last updated at Posted at 2020-09-29

サンプル文

引数に渡した配列をシャッフルして返す。

test.js
function shuffle(arr) {
    for (let i = arr.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      [arr[j], arr[i]] = [arr[i], arr[j]];
    }
    return arr;
  }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0