Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active September 22, 2017 23:11
Show Gist options
  • Save vielhuber/6aa304d08dc099e9e9e9 to your computer and use it in GitHub Desktop.
Save vielhuber/6aa304d08dc099e9e9e9 to your computer and use it in GitHub Desktop.
make intersection / cut between arrays of arrays #js
var arr = [
['a', 'b', 'c', 'd', 'a'],
['c', 'd', 'e'],
['b', 'c', 'd', 'd']
];
var arr = arr.shift().reduce(function(res, v) {
if (res.indexOf(v) === -1 && arr.every(function(a) {
return a.indexOf(v) !== -1;
})) res.push(v);
return res;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment