{"push_id":735914444,"size":1,"distinct_size":1,"ref":"refs/heads/patch-2","head":"64d369739a413c9a95715c54a710ff713216813f","before":"21085564624fef6fb7149d7b92580b3937ac3f43","commits":[{"sha":"64d369739a413c9a95715c54a710ff713216813f","author":{"email":"70cd74d6cf8da9076e13b45876fe09ff22453474@gmail.com","name":"Luke Zilioli"},"message":"Refactor monkeys004.js to incorporate feedback.\n\n- You do not need the \"use strict\" statement at the top of every function. You can instead put it at the top of the file, and every function within will also be run in strict mode. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode?redirectlocale=en-US&redirectslug=JavaScript%2FStrict_mode\r\n- The .prototype.methodName = function() syntax is good, and I use it frequently in my code as well. Check out some examples from my snips project: https://github.com/lzilioli/snips (in the lib/ directory)\r\n- .charAt() is not usually necessary for string access, unless you are working with unicode characters. Since in this case your alphabet is all ascii characters, you can get away with using [] to access your string rather than .charAt https://mathiasbynens.be/notes/javascript-unicode\r\n- at the bottom, you dont need to declare a typewriter array, just declare var typewriter = new Typewriter(\"abcde\") and use your typewriter variable\r\n- The way this is designed, you need to define a new Typewriter everytime you want to try to type out a new phrase. This is fine given the way your typewriter is implemented, since it uses a lot of internal state to keep track of what its doing. I understand that you did it this way to get practice with OOP, but just wanted to mention that typically the same problem would not be solved via OOP in practice.\r\n- in your answer method, you do not need to build up the story_so_far variable. Since you already know how many characters you have successfully matched (stored in best_guess), you can simplify that entire method down to one line: `return ('found ' + story.substring(0, this.best_count) + ' after ' + this.guess_count + ' guesses');` (if you do this, it exposes a bug in your code: `best_count` does not get incremented on the final attempt when it successfully finds the correct story. There is below feedback on how to refactor `match_advanced` to eliminate this bug.\r\n- In general, its good to avoid naming variables such that their english name contains a negative, and instead negate your variable in your if statements. It makes it difficult to reason about the variable's value. eg. `incomplete = true` VS `complete = false`. Which is more straightforward to think about? Consider `!incomplete` vs `complete`. `!complete` is a much more straightforward way to represent completion.\r\n- a few places in the code, you increment a variable by 1 via `variable += 1`. You can shorten that to `variable++`;\r\n- in `match_advanced`, you only increment the `guess_count` variable in the else case. Since `match_advanced` means that a match was found, you can safely increment `guess_count` at the top of the method. If you make that change, you can remove the -1 from the if statement. The flow for that method can be simplified to:\r\n-- increment `guess_count`\r\n-- if `guess_count > best_count`\r\n--- assign `guess_count` to `best_count`, and `console.log(this.answer())`\r\n--- check if `guess_count` is the same as the length of the story, and if it is set complete to true\r\n with the above change to `match_advance`, you can remove the `console.log(typewriter.answer())` after your while loop","distinct":true,"url":"https://api.github.com/repos/lzilioli/monkeys/commits/64d369739a413c9a95715c54a710ff713216813f"}]}