The First Solution Is Not Always the Best
One thing I’ve learned while coding is that getting something to work is only the first step.
For example, imagine you need to filter users by their role. You could quickly write the same filtering logic in several components:
```js
users.filter(user => user.role === "admin")
```
It works. But if you find yourself repeating that logic across the application, it may be worth moving it into a reusable function:
```js
const getAdmins = users =>
users.filter(user => user.role === "admin");
```
Now the code is easier to reuse, test, and maintain.
Sometimes the first solution solves the problem, but taking a moment to step back can help you find a cleaner one.
“Does it work?” is important.
But “Can I make this simpler and easier to maintain?” is another question worth asking.
What’s a coding solution you’ve improved after getting it to work the first time?
View passport