Following this principle code example 2 (i.e. Javascript after deduplication) would be the sweet spot. It fulfills the requirements without in the most obvious way, at a good level of abstraction (the requirements did not make any of the three pictures specific -- defining a separate function for each actually goes beyond the requirements, while obscuring the higher-level goal).
All of the subsequent examples focus on using the features of the platform rather than clearly showing the purpose of the code, i.e. unnecessarily obfuscate it.