Created
December 8, 2021 05:52
-
-
Save leyanlo/28434c2bc80134489023dd56b7884b10 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
const exampleSignals = | |
'acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab'; | |
const charCount = {}; | |
for (const char of exampleSignals | |
.split('') | |
.filter((char) => /[a-g]/.test(char))) { | |
charCount[char] = (charCount[char] ?? 0) + 1; | |
} | |
function charCountSum(signal) { | |
return signal.split('').reduce((acc, char) => acc + charCount[char], 0); | |
} | |
const charCountSumToDigit = { | |
[charCountSum('acedgfb')]: 8, | |
[charCountSum('cdfbe')]: 5, | |
[charCountSum('gcdfa')]: 2, | |
[charCountSum('fbcad')]: 3, | |
[charCountSum('dab')]: 7, | |
[charCountSum('cefabd')]: 9, | |
[charCountSum('cdfgeb')]: 6, | |
[charCountSum('eafb')]: 4, | |
[charCountSum('cagedb')]: 0, | |
[charCountSum('ab')]: 1, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment