DEV Community

Discussion on: Learning Algorithms with JS, Python and Java 7: Anagrams

Collapse
 
kepta profile image
Kushan Joshi • Edited

This is a great solution Sam, the only thing I worry about is that multiplication though theoretically is an O(1) operation, but in for strings of size > 50, we will have resort to Big integers and multiplication there is not exactly O(1).

Also played a bit of code golf with your algorithm

const primeSum = word =>
  word
    .map(char => primes.get(char.toLowerCase()))
    .filter(char => char !== undefined)
    .reduce((prev, cur) => prev * cur);