Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Forked from padolsey/a.md
Last active December 18, 2015 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badsyntax/5728001 to your computer and use it in GitHub Desktop.
Save badsyntax/5728001 to your computer and use it in GitHub Desktop.
function f(a, b) {
a = a.split('');
b = Array.prototype.slice.call(arguments, 1).join('').split('');
return a.filter(function(val, i, arr) {
return ~b.indexOf(val) && a.indexOf(val) === i
}).join('')
}
@padolsey
Copy link

padolsey commented Jun 7, 2013

Nice! Just updated mine to include any characters. Only issue with my approach is the returned string is not a unique set of characters, it may contain repeats in cases of, e.g. f('aa', 'a')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment