I'm new to JS and often do these challenges to learn JS well.
I'm here trying to work with a nested loop and trying to create a function which should returns values from schoolsB
array that isn't in schoolsA
so the expected output I want is:
"Edify", "Beacon House"
I think I'm halfway there with the if-else but instead, it's returning only values that are present in both arrays however I want something else!
I tried doing this:
if (!(arr2[i].includes(arr1[j]))) {
but this also didn't work!
Where am I mistaking?
PS: I do know I can simply use a filter method to achieve what I want but I wanna learn to use this too!
let schoolsA = ["Aman", "Shoeby", "Rose"];
let schoolsB = ["Aman", "Shoeby", "Edify", "Beacon House"];
function filtering(arr1, arr2) {
let output = [];
for (let i = 0; i < arr2.length; i++) {
for (let j = 0; j < arr1.length; j++) {
if (arr2[i].includes(arr1[j])) {
output.push(arr2[i]);
}
}
}
return output;
}
console.log(filtering(schoolsA, schoolsB));