Use the modern boilerplate. It may need some updates.
This is an algorithm to find subsets that can be replaced.
for (let i = 0; i < arr.length; i++) { if (arr[i] === comboType[0]) { let flag = true; for (let j = 1; j < comboType.length; j++) { if (arr[i + j] !== comboType[j]) flag = false; } if (flag) { return arr.splice(i, comboType.length, 'combined'); } } }