Skip to content

Instantly share code, notes, and snippets.

@cezary
Last active February 9, 2018 22:41
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 cezary/9fd5527b833228d5d8810d4c347894de to your computer and use it in GitHub Desktop.
Save cezary/9fd5527b833228d5d8810d4c347894de to your computer and use it in GitHub Desktop.
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