🚑 Prevent duplicate substitutions within a file
This commit is contained in:
@ -39,10 +39,24 @@ export class Parser {
|
|||||||
const dayPlans = [];
|
const dayPlans = [];
|
||||||
for (const plan of plans) {
|
for (const plan of plans) {
|
||||||
const foundPlan = dayPlans.find((e) => e.date == plan.date);
|
const foundPlan = dayPlans.find((e) => e.date == plan.date);
|
||||||
if (!foundPlan) dayPlans.push(plan);
|
if (!foundPlan) {
|
||||||
else {
|
// Make sure to not insert duplicate substitutions within a file
|
||||||
|
const changes = structuredClone(plan.changes);
|
||||||
|
const cleanedChanges = [];
|
||||||
|
for (const change of changes) {
|
||||||
|
const changeExists = cleanedChanges.find(
|
||||||
|
(e) => JSON.stringify(e) == JSON.stringify(change),
|
||||||
|
);
|
||||||
|
if (!changeExists) {
|
||||||
|
cleanedChanges.push(change);
|
||||||
|
}
|
||||||
|
// Use the new array of changes
|
||||||
|
plan.changes = cleanedChanges;
|
||||||
|
}
|
||||||
|
dayPlans.push(plan);
|
||||||
|
} else {
|
||||||
for (const change of plan.changes) {
|
for (const change of plan.changes) {
|
||||||
// Make sure to not insert the exact same substitution twice
|
// Make sure to not insert a substitution that already exists in the changes
|
||||||
const changeExists = foundPlan.changes.find(
|
const changeExists = foundPlan.changes.find(
|
||||||
(e) => JSON.stringify(e) == JSON.stringify(change),
|
(e) => JSON.stringify(e) == JSON.stringify(change),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user