How does JS regularity judge six consecutive numbers

for example, 123456, 456789, 876543

Apr.03,2021

directly for loop record the last digit to determine whether the number is continuous


regular is not suitable for this job as upstairs


(0 = 1) | 1 (? = 2) | 2 (? = 3) | 3 (? = 4) | 4 (? = 5) | 5 (? = 6) | 6 (? = 7) | 7 (? = 8) | 8 (?)) {5} d can match positive order
change or reverse order, but judge twice

Let's use a loop, a loop to get it done

function isContinuityNum(num){

  let arr=Array.from(num.toString())
  let arr1= [...arr]
  arr.reverse()
  
  arr3 = arr1.map((n,i)=>{
    return parseInt(n)+parseInt(arr[i])
  })
  
  return [...new Set(arr3)].length === 1

}

var d=isContinuityNum(num)
console.log(d)

regularization needs to be done twice. First, replace 7 digits or more, and then the longest string left is only 6 digits. In this case, you only need to match 6 digits. There is no interference with long numbers.


discuss the importance of Baidu

quoted from: https://bbs.csdn.net/topics/3.

var number = '123456';
var str = number.replace(/\d/g, function($val, pos) {
    return parseInt($val) - pos;
});
console.log(/^(\d)\1+$/.test(str));

var number = '654321';
var str = number.replace(/\d/g, function($val, pos) {
    return parseInt($val) + pos;
});
console.log(/^(\d)\1+$/.test(str));
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ead143-2128.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ead143-2128.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?