从最后一个元素开始,从数组中随机选出一个位置,交换,直到第一个元素。

    function disorder(array) {
      const length = array.length;
      let current = length - 1;
      let random;
      while (current >-1) {
        random = Math.floor(length * Math.random());
        [array[current], array[random]] = [array[random], array[current]];
        current--;
      }
      return array;
    }
Last Updated: 8/4/2019, 9:33:54 PM