stringtest.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const fs = require('fs')
  2. let fp1: string = '' // data
  3. let fp2: string = '' // output
  4. // let fp3: string = '' // fingerprint
  5. fs.readFile('data.txt', (err, fingerprint) => {
  6. if (err) throw err;
  7. fp1 = fingerprint.toString()
  8. // console.log(fp1.length);
  9. })
  10. fs.readFile('fingerprint.txt', (err, fingerprint) => {
  11. if (err) throw err;
  12. fp2 = fingerprint.toString()
  13. // console.log(fp2.length);
  14. })
  15. // fs.readFile('fingerprint.txt', (err, fingerprint) => {
  16. // if (err) throw err;
  17. // fp3 = fingerprint.toString()
  18. // // console.log(fp3);
  19. // })
  20. const mismatches: number = compareAndCountDifferences(fp1, fp2);
  21. console.log(`Number of mismatches: ${mismatches}`);
  22. function compareAndCountDifferences(str1, str2): number {
  23. // Length validation:
  24. if (str1.length !== 151440 || str2.length !== 151440) {
  25. console.log("Error: Strings must be exactly 151440 characters long")
  26. }
  27. // Character comparison and difference counting:
  28. let differenceCount = 0;
  29. for (let i = 0; i < str1.length; i++) {
  30. if (str1[i] !== str2[i]) {
  31. differenceCount++;
  32. }
  33. }
  34. return differenceCount;
  35. }