Skip to content

Instantly share code, notes, and snippets.

@h2ospace
Created March 14, 2013 19:37
Show Gist options
  • Save h2ospace/5164472 to your computer and use it in GitHub Desktop.
Save h2ospace/5164472 to your computer and use it in GitHub Desktop.
underscore: union, intersection, difference, uniq
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Underscore</title>
<script src="underscore-min.js"></script>
</head>
<body>
<script>
(function() {
var a = [1, 2, 5];
var b = [5, 2, 8];
var x;
x = _.union(a, b); // 集合
x = _.intersection(a, b); // a, bにある要素
x = _.difference(a, b); // どちらかしかない
x = _.uniq([2, 5, 2, 10, 5]);
console.log(x);
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment