This function is designed to remove duplicate items from an array:
removeDuplicates(item: String, allForToday: Array) {
let temp = allForToday;
for (let i = 0; i < temp.length; i++) {
if (temp[i].indexOf(item) > -1) {
temp = temp.splice(i, 1);
}
}
return temp;
}
To use this function, you would call it like this:
for (let i = 0; i < lastWeekItems.length; i++) {
allForToday = t.removeDuplicates(lastWeekItems[i], allForToday);
}
The parameter lastweekItems[i]
is a string, and allForToday is an array of strings in the format: 1;2;3
. For example, lastweekItems[i] could be 2
. The expected behavior is for the entire array to be checked for each item, removing any occurrences found. However, the observed behavior is that only temp[0] is checked, leading to the entire remaining portion of the array being spliced, resulting in an empty array (temp.length changes from 14 to 1)...