知足最小分組的長度爲其餘分組的整數倍javascript
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 }