Created
December 14, 2013 03:48
-
-
Save gh640/7955465 to your computer and use it in GitHub Desktop.
JavaScript function to check 2 arrays have any common element or not. return true or false.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to check 2 arrays have any common element or not | |
// @return | |
// matched : true/false | |
// @args | |
// a1 :: array | |
// a2 :: array | |
function commonElementExist(a1, a2){ | |
var matched = false; | |
a1.forEach(function(e1){ | |
if(a2.indexOf(e1) != -1){ | |
matched = true; | |
return false; | |
} | |
}); | |
return matched; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment