Created
May 10, 2019 16:56
-
-
Save tarzak/9eb1414042f89564fb0d0149e3d7e8e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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