lrwong / crackthecode

0 stars 0 forks source link

Hash solution #2

Open Tzeak opened 7 years ago

Tzeak commented 7 years ago

For the hash solution, I'm inclined to say the initial solution where you pushed 0 everywhere was better. When you allocate a new Array, does it zero out the data? probably. this is only really an issue i imagine for C lol

also, charCodeAt(i) would return the ascii value of the letter. If the string were "ABC" and charCodeAt(0) == 65, would hash[65] be out of bounds

probably another C problem. how about you teach me javascript

lrwong commented 7 years ago

it allocates to undefined, which is why I used the first solution. but I need to fix the hash, should be let x = ... - 65;

Tzeak commented 7 years ago

New issue with this solution - you use something called magic numbers, where charCodeAt(x) - 97 to get the answer. Try to avoid numbers like that. Define a variable that describes the number (or at least use comments to explain whats going on/what reasoning is behind this) ALternatively you could do charCodeAt(x) - 'A' -- any language that's loosely typed will allow this. If they're strictly typed, there's probably some sort of conversion auxiliary function charToInt or something.