From my experience, answers on this site that are literally just code don't really help all that much except for solving that specific problem.
This is a nuance in in Q&A that is overlooked in that, the basic contract of Q&A is someone receiving an answer for asking a question.
So I'm going to tell you something that's highly controversial.
A code-only answer is still an answer. With that, the expectation of Q&A is met and the person who asked their question may be satisfied with the answer.
Now I'm going to pull that back a bit since it's obvious that we do prefer answers that offer more of an explanation rather than someone just putting their code here and saying, "here, try this".
A code-only answer is still an answer. It's just not a very good answer by Stack Overflow's standards.
In that event, I prefer to just downvote those kinds of answers. They're not really helpful, so there's no reason to presume any circumstance of hurt feelings by indicating that their quality isn't up to par.
...but I want to be clear, they're still answers. You can't get mad at someone for literally doing what they were asked.