const compareArraysExceptIndices = (xs, ys, is = [], alts = []) =>
xs.reduce((prev, curr, index) => {
const isMatch = ys[index] === curr
const isValidAlternative = alts.length
? is.includes(index) && alts.includes(ys[index])
: is.includes(index)
return prev && (isMatch || isValidAlternative)
}, true)
console.log(compareArraysExceptIndices([1,2,3], [1,2,3])) // true
console.log(compareArraysExceptIndices([1,2,3], [1,1,3])) // false
console.log(compareArraysExceptIndices([1,2,3], [1,1,3], [1])) // true
console.log(compareArraysExceptIndices([1,2,3], [1,1,3], [1], [1])) // true
console.log(compareArraysExceptIndices([1,2,3], [1,1,3], [1], [2])) // true
This will handle all the cases you're asking about.