When using expressions like "(++memo[type]) || 1", it would be a good idea to add some comments in the function to explain it :D