js数组的随机排序并按固定长度分割成多个数组

定义一个1-52数字的数组

 let arr = []
      for (let i = 0; i < 52; i++) {
        arr[i] = i + 1
      }

对该数组的随机排序

      arr.sort(function () {
        return Math.random() - 0.5
      })

对随机排序的数组按固定长度分割并生成新数组

  cutArray (array, subLength) {
    let index = 0
    let newArr = []
    while (index < array.length) {
      newArr.push(array.slice(index, index += subLength))
    }
    return newArr
  }
       return this.cutArray(arr, 13)

你可能感兴趣的:(es6,笔记)