I have a JS logic that I am trying to implement, and now pondering why it is not working: I have two arrays with at least one similar element in them, but implementing the logic returned false
- but I was expecting the opposite result. Please take a look:
const array_one = [
"Apparel",
"Footwear",
];
const array_two = [
"Soap",
"Footwear",
];
const checkArray = (arr1, arr2) => {
if (arr1.length !== arr2.length) {
return false;
} else {
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
}
return true;
};
console.log(checkArray(array_one, array_two)); //logs false to the console, was expecting 'true'.