Created
November 29, 2023 17:46
-
-
Save raikusy/f47060f5c403b2878618d0ee07c84e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixSerialNumbers(data) { | |
// Functions for number conversions | |
const toEn = (n) => n.replace(/[০-৯]/g, (d) => "০১২৩৪৫৬৭৮৯".indexOf(d)); | |
const toBn = (n) => n.replace(/\d/g, (d) => "০১২৩৪৫৬৭৮৯"[d]); | |
// A helper function to pad the serial number with leading zeros | |
const padSerial = (num) => num.toString().padStart(4, "0"); | |
// Set to keep track of used serial numbers | |
let usedSerials = new Set(); | |
// Iterate through the data and fix serial numbers | |
for (let i = 0; i < data.length; i++) { | |
let base; | |
// For the first 15 entries, follow the initial pattern | |
base = (i % 5) * 3 + Math.floor(i / 5) + 1; | |
while (usedSerials.has(toBn(padSerial(base)))) { | |
base += 3; | |
} | |
let expectedSerial = toBn(padSerial(base)); | |
usedSerials.add(expectedSerial); // Add to used serials | |
console.log(`${expectedSerial} ---- ${data[i]["Serial Number"]}`); | |
// Fix the serial number if it doesn't match the expected pattern | |
if (data[i]["Serial Number"] !== expectedSerial) { | |
data[i]["Serial Number"] = expectedSerial; | |
} | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment