Jason Gorman demonstrates the refactoring discipline - arguably one of the most important skills for a software developer, and also one of the most undervalued.
Read the book:
Refactoring (Martin Fowler)
/ 44936.refactoring
Source code (un-refactored)
https://github.com/jasongorman/js_ref...