In my current project, I am dealing with a function that takes in two variables. These variables are subject to change at any point during the execution of the program. My requirement is to identify which variable has changed so that further operations can be performed based on that specific variable.
I am looking for a method that can differentiate between the two types of variables (integer and string) and provide me with the information about which variable has changed in order to manipulate it for subsequent operations.
private checkValues(param1: number, param2: string) {
// Check values in array by Test
for(let test of this.valuesT){
if(test === param2 ){
this.flagT = true;
// console.log(this.flagT);
}
}
// Check values in array by testNumber
for(let testN of this.valuesTN){
if(testN === param1){
this.flagTN = true;
}
}
// First validation every
if(this.flagT && this.flagTN){
return param1
}
// Return testNumber if exist changes
if(this.flagT && !this.flagTN){
this.valuesTN.push(param1)
return param1
}
// Return test if exist changes
if(this.flagTN && !this.flagT){
this.valuesT.push(param2)
return param2
}
}
I have implemented a method that tracks the changes in variables based on their previous states stored in an array. However, this approach restricts the ability to revert back to a previous state as the data is already stored in the array.
Initially, both variables are set to the same value and are stored in the array. As a result, initially, both flags will be true.
Do you have any suggestions for improving this implementation?