Created
January 15, 2015 04:30
-
-
Save bamoo456/b16842dc6f54df8e2220 to your computer and use it in GitHub Desktop.
js simple gist
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
/** | |
* @Author: George_Chen | |
* @Description: get the union of two array | |
* | |
* @param {Array} arr1, an basic array including some elements | |
* @param {Array} arr2, an basic array including some elements | |
*/ | |
function __getArrayUnion(arr1, arr2) { | |
var union = {}; | |
var len = (arr1.length > arr2.length) ? arr1.length : arr2.length | |
for (var i = 0; i < len; ++i) { | |
if (!!arr1[i]) { | |
union[arr1[i]] = true; | |
} | |
if (!!arr2[i]) { | |
union[arr2[i]] = true; | |
} | |
} | |
return Object.keys(union); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment