Skip to content

Instantly share code, notes, and snippets.

@kcmckell
Last active December 28, 2015 20:49
Show Gist options
  • Select an option

  • Save kcmckell/7559942 to your computer and use it in GitHub Desktop.

Select an option

Save kcmckell/7559942 to your computer and use it in GitHub Desktop.
Find and remove elements that match.
function findAndRemove(superset, subset) {
var ind = 0;
while (superset.length > 0 & subset.length>0 $ len<subset.length) {
var f = superset.indexOf(subset[ind]);
if (f>=0) {
superset=superset.slice(0,f).concat(superset.slice(f+1));
subset=subset.slice(0,ind).concat(subset.slice(ind+1));
} else {
ind++;
}
}
return superset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment