function isStraight(arr) {
let max = 0,min=14,kingNum=0
let amap = {
A: 1,
J: 11,
Q: 12,
K: 13,
小王: -1,
大王: -1
}
for (let i = 0; i < arr.length; i++) {
arr[i] = amap[arr[i]] ? amap[arr[i]] : arr[i]
if (arr[i] === -1) {kingNum++;continue}
if(arr[i]<min) min = arr[i]
if(arr[i]>max) max = arr[i]
}
let set = new Set(arr)
// 检查是否重复
if(set.size<arr.length) return false
// 根据最大值与最小值的间隔数判断是否顺子
if(max-min>4) return false
return true
}
console.log(isStraight([1, 2, 4, 5,'小王']))
function getRadomArr(){
let dataSource = ['A',1,2,3,4,5,6,7,8,9,10,'J','Q','K','小王','大王']
let rs = []
for (let i = 0; i < 5; i++) {
let index = Math.floor(Math.random() * 16)
rs.push(dataSource[index])
}
return rs
}
function test() {
let testArr = getRadomArr()
console.log('测试数据:',testArr.join(','))
console.log('测试结果:',isStraight(testArr))
}
console