满足最小分组的长度为其他分组的整数倍
export default (arr) => { // 对这副牌进行排序,升序、降序都可以 arr.sort((a, b) => a - b) let min = Number.MAX_SAFE_INTEGER let dst = [] let result = true for (let i = 0, len = arr.length, tmp = []; i < len; i++) { tmp.push(arr[i]) for (let j = i + 1; j < len - 1; j++) { if (arr[i] === arr[j]) { tmp.push(arr[j]) } else { if (min > tmp.length) { min = tmp.length } // 因为数组为引用类型,直接push会导致出错 dst.push([].concat(tmp)) tmp.length = 0 i = j break } } } dst.every(item => { if (item.length % min !== 0) { result = false return false } }) return result }
来源:https://www.cnblogs.com/ygjzs/p/12234070.html