The program is as follows. It can run and produce results, but it will report an error... It's very strange and I have no idea where to start...
Code:
function pad(str, len) {
return '0'.repeat(len-str.length) + str
}
function numberAndIPaddress(s){
if (s.indexOf('.')) {
let numbers = s.split('.').map(x=>{ return pad( parseInt(x).toString(2), 8 ) })
return parseInt( numbers.join(''), 2 )
} else {
let number = pad( parseInt(s).toString(2), 32 )
return [ parseInt( number.slice(0, 8), 2),
parseInt( number.slice(9, 16), 2),
parseInt( number.slice(17, 24), 2),
parseInt( number.slice(25, 32), 2)
].join('.')
}
}
console.log( 'result', numberAndIPaddress("10.0.3.193") )
// console.log( numberAndIPaddress("167969729") )
Output:
Give it a try. Currently your code runs without any problem. But if you run the code you commented out, you will get an error very similar to the screenshot. The reason is that
len-str.length
is a negative number. You can debug it and see.In addition, although eslint may also report this error, it does not appear from your error message that it comes from eslint.
You can refer to this issue first: https://github.com/eslint/esl...
It may happen in the following line: