Last active
February 9, 2018 22:41
-
-
Save cezary/9fd5527b833228d5d8810d4c347894de 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 letterMap = { | |
"A": 2, | |
"B": 3, | |
"C": 5, | |
"D": 7, | |
"E": 11, | |
"F": 13, | |
"G": 17, | |
"H": 19, | |
"I": 23, | |
"J": 29, | |
"K": 31, | |
"L": 37, | |
"M": 41, | |
"N": 43, | |
"O": 47, | |
"P": 53, | |
"Q": 59, | |
"R": 61, | |
"S": 67, | |
"T": 71, | |
"U": 73, | |
"V": 79, | |
"W": 83, | |
"X": 89, | |
"Y": 97, | |
"Z": 101 | |
}; | |
function stringProduct(str) { | |
return str | |
.toUpperCase() | |
.split('') | |
.reduce((acc, char) => acc * letterMap[char], 1); | |
} | |
function isAnagram(a, b) { | |
return stringProduct(a) === stringProduct(b); | |
} | |
isAnagram('hello', 'olleh'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment