The below code runs a function to remove apostrophes from two arrays then compares them to see if they are the same.
var array1 = ["ohara"];
var array2 = ["o'hara"];
function convertSpecial(a,b,c) {
let aCopy = [...a];
for (let i = 0; i < aCopy.length; i++) {
if (aCopy[i].includes(b)) {
if (c == '') {
aCopy[i] = aCopy[i].replace(b,c);
} else {
aCopy[i] = aCopy[i].replace(b,c).split(' ');
aCopy = aCopy.flat();
}
}
}
return aCopy;
}
var changed1 = convertSpecial(array1,"'","");
var changed2 = convertSpecial(array2,"'","");
console.log(changed1); // returns ["ohara"]
console.log(changed2); // returns ["ohara"]
console.log((changed1 == changed2)); //returns false, should be true
I am expecting the two arrays to be the same, but they are not. Why?