Skip to content

Instantly share code, notes, and snippets.

@bamoo456
Created January 15, 2015 04:30
Show Gist options
  • Save bamoo456/b16842dc6f54df8e2220 to your computer and use it in GitHub Desktop.
Save bamoo456/b16842dc6f54df8e2220 to your computer and use it in GitHub Desktop.
js simple gist
/**
* @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