SO-33461584
by David Thomas
JavaScript
// naming the function, defining the
// arguments to pass:
function commonElements(arr1, arr2) {
// iterating over arr1, using
// Array.prototype.some() wherein
// 'el' is the current element of
// the array over which we're iterating:
return arr1.some(function (el) {
// finding the 'el' value in
// arr2; and comparing the index
// if the 'el' value isn't found
// in arr2 it returns -1:
return arr2.indexOf(el) > -1;
});
}
var one = [1, 2, 3, 4, 5],
two = [5, 6, 7, 8, 9];
console.log(commonElements(one, two)); // true