预期
[1,2,3,4,5] => true
[1,2,3,5,6] => false
代码
//判断一串数字是否是连续的
const isContinuityNum = (num: number[] | number) => {
let array = [];
if (num instanceof Array) {
array = [...num];
} else {
array = Array.from(num.toString()); //转换为数组
}
let i = array[0];
let isContinuation = true;
for (let e in array) {
if (array[e] != i) {
isContinuation = false;
break;
}
i++;
}
return isContinuation;
};
测试
标签:false,数字,isContinuation,js,num,let,数组,array From: https://www.cnblogs.com/ifnk/p/16634730.html