function comparing two arrays and returning a Boolean
Wed Apr 26 2023 16:35:37 GMT+0000 (Coordinated Universal Time)
Saved by
@thecowsays
#javascript
const sandwichOne = ["white bread", "lettuce", "brown bread"];
const sandwichTwo = ["white bread", "tomato", "white bread"];
function compareBread(array1,array2) {
let sameBread;
if ((array1[0] === array2[0]) && (array1[array1.length - 1] === array2[array2.length - 1])) {
console.log("Both tops and bottoms are the same!");
return true;
} else {
console.log("They both use different bread -- WEIRDO!");
return false;
}
}
compareBread(sandwichOne,sandwichTwo);
content_copyCOPY
change the bread type on sandwichOne from "brown bread" to "white bread" and watch the function return TRUE instead
Comments