0

So I have two serial numbers and 199 serials in between them:

899720101000105500 (first)

899720101000105699 (last)

I need to print the first serial and then all 199 up to the last serial. The only thing I've found is just +1 to the first serial every time the loop runs and printing it.

I've copied/pasted different parts and this is what I have:

var lowEnd = 899720101000105500;
var highEnd = 899720101000105699;
var arr = [];
while(lowEnd <= highEnd){
   arr.push(lowEnd++);
}

Is there a max number length you can store in a variable?

  • 2
    `Number.MAX_SAFE_INTEGER` which should be `9007199254740991` or `2^53 - 1`. – fuyushimoya Aug 19 '15 at 17:51
  • See [What is JavaScript's highest integer value that a Number can go to without losing precision?](http://stackoverflow.com/q/307179/1737627) for more details. – fuyushimoya Aug 19 '15 at 17:57
  • You can test that `lowEnd === lowEnd + 1` which is `true`, so it's not safe for you to do that, convert them to `string`, or split them to many smaller `number`s, then do the calculation. – fuyushimoya Aug 19 '15 at 17:59
  • Ah I see. That's smaller than my number. How would you recommend I cut it up? that last 4 numbers (5500 and 5699) are to only unique digits in the number so maybe make the first numbers a string, count 5500 to 5699 and then append to the string of the first digits? – Blake Enloe Aug 19 '15 at 18:33
  • Yes, if you already know only the last 4 digits will change, that's should be a good solution. – fuyushimoya Aug 19 '15 at 18:45

2 Answers2

0

Here's the solution for this specific problem for anyone that may come across this. Make the static parts of the number (the digits that don't change) a string and just use the digits that do change (for me it was the last 4) to count and then add the string to the count and log it.

var serialNumber = 5500;

while(serialNumber <= 5699)
{
    serialNumber = serialNumber + 1;
    var fullNumber = "89972010100010" + serialNumber;
    console.log(fullNumber);
}
0
 for (let i = BigInt(899720101000105500); i <= 899720101000105699; BigInt(i++)) {        
         console.log(i + '')        
 }
  • 2
    You should avoid code-only answers. Answers that provide a rationale are much more likely to be helpful – GuedesBF May 26 '21 at 21:01