Skip to content

Instantly share code, notes, and snippets.

@tarzak
Created May 10, 2019 16:56
Show Gist options
  • Save tarzak/9eb1414042f89564fb0d0149e3d7e8e8 to your computer and use it in GitHub Desktop.
Save tarzak/9eb1414042f89564fb0d0149e3d7e8e8 to your computer and use it in GitHub Desktop.
var unique = 'ab';
var all = 'Aaabbb';
var uniqueArr = unique.split('');
var allArr = all.split('');
function converToObj(accum, currentEl) {
if (!accum[currentEl]) accum[currentEl] = true;
return accum;
};
var uniqueObj = uniqueArr.reduce(converToObj, {});
function countThisShit(sum, currentEl) {
if (uniqueObj[currentEl]) sum += 1;
return sum;
};
allArr.reduce(countThisShit, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment