Skip to content

Commit

Permalink
fix: Check for leading zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese committed Nov 13, 2023
1 parent c524fc4 commit a985723
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ function increment(string, amount) {
// Store number's length
var numberLength = number.length;
var leadingZeroes = number.startsWith("0");

// Increment number by the amount
number = (parseInt(number, 10) + parseInt(amount, 10)).toString();

// If there were leading 0s, add them again
if(leadingZeroes) {
if (leadingZeroes) {
while (number.length < numberLength) {
number = "0" + number;
}
Expand Down

0 comments on commit a985723

Please sign in to comment.