Skip to content

Instantly share code, notes, and snippets.

@alldayalone
Last active January 26, 2020 10:40
Show Gist options
  • Save alldayalone/b0baaf756faf3d4ca3c623b56e4069c2 to your computer and use it in GitHub Desktop.
Save alldayalone/b0baaf756faf3d4ca3c623b56e4069c2 to your computer and use it in GitHub Desktop.
Difference
function difference(a, b) {
var result = [];
for (var i = 0; i < a.length; i++) {
if (b.indexOf(a[i]) === -1) {
result.push(a[i]);
}
}
return result;
}
console.log(difference([1, 3, 2, 4, 5], [1, 5, 4]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment