function syncStringsByTag(str1: string, str2: string, tag: string): [string, string] {
let lines1 = str1.split('\n');
let lines2 = str2.split('\n');
const maxLength = Math.max(lines1.length, lines2.length);
lines1 = lines1.concat(Array(maxLength - lines1.length).fill(''));
lines2 = lines2.concat(Array(maxLength - lines2.length).fill(''));
for (let i = 0; i < maxLength; i++) {
const hasTag1 = lines1[i].includes(tag);
const hasTag2 = lines2[i].includes(tag);
if (hasTag1 && !hasTag2) {
lines1 = lines1.concat('');
} else if (!hasTag1 && hasTag2) {
lines2 = lines2.concat('');
const syncedStr1 = lines1.join('\n');
const syncedStr2 = lines2.join('\n');
return [syncedStr1, syncedStr2];
const str1 = "Line 1\nLine 2\n<t>Tag 1</t>\nLine 4";
const str2 = "First Line\n<t>Tag 2</t>\nThird Line\nFourth Line";
const [syncedStr1, syncedStr2] = syncStringsByTag(str1, str2, '<t>');
console.log('Synced String 1:\n', syncedStr1);
console.log('Synced String 2:\n', syncedStr2);