Some solutions (6)
let student1Courses = ['Math', 'English', 'Programming', 'd']; let student2Courses = ['Geography', 'd', 'Spanish', 'Programming'];
const filterArray = student1Courses.filter(value => student2Courses.includes(value));
function filterArray(){ const diff = []; for (let i = 0; i < student1Courses.length; i++) { const val1 = student1Courses[i];
for (let j = 0; j < student2Courses.length; j++) { const val2 = student2Courses[j]; if (val2.includes(val1) ) { diff.push(val2); console.log(diff); } } }
}
filterArray();
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Some solutions (6)
let student1Courses = ['Math', 'English', 'Programming', 'd'];
let student2Courses = ['Geography', 'd', 'Spanish', 'Programming'];
const filterArray = student1Courses.filter(value => student2Courses.includes(value));
function filterArray(){
const diff = [];
for (let i = 0; i < student1Courses.length; i++) {
const val1 = student1Courses[i];
}
filterArray();