🔁 One of the simplest refactors that made me a better developer. I used to write a brand new function every time requirements changed. Copy. Paste. Tweak. Repeat. It worked - but it didn’t scale. At some point I started asking a different question: “What’s actually changing here?” Most of the time, it wasn’t the structure — just the operation. So instead of rewriting logic, I abstracted it. One function. Different behavior passed in when needed. (In JavaScript terms, the outer function becomes a higher-order function, and the behavior we pass in is a callback.) That shift - from hardcoding logic to designing flexibility - was where clean code started making sense to me. Once it clicks, you begin noticing it everywhere: how libraries are designed, how experienced engineers structure systems, and why good code survives changing requirements. #JavaScript #WebDevelopment #CleanCode #Programming #SoftwareEngineering
I don't understand... `transform` is Array.map, isn't it? And it's also not as well-named... filter, map, reduced are all transformations of the array... So you've blurred that. So you'd want to call your new function: arrayWithFunctionAppliedToItsValues (As Mikhail Klivekin implies) What you really want to say is ... "My array, with all the values mapped to their addTwo". JavaScript has language for that... You're starting to create a new Domain Specific one -- but for a domain that is doing stuff with arrays, which is in the core language. The pedantic refactor would be to give a name to the anonymous function.
Absolutely agree - One well-designed function can replace multiple copy-paste variants!!
After removing all unnecessary: [1, 2, 3].map(x => x + 3)