WTH is there no "function" capability

I would like the ability to create/use functions in the true sense of programming. It would be really nice to create something like a script where you could pass in values/parameters and have it return a result back to where it was called from.

This would help eliminate needing multiple exact copies of the same code to do the same thing in automations or scripts. My thought is that they could be used like a template to do the complicated logic and return the value.

{{ function('function.time_difference', input_datetime.time1, input_datetime.time2) }}

The example above would call the function “time_difference” that performs a calculation between the two passed input_datetime objects - and the result of that calculation function would be returned as the template value. Please note this is just a single example - this could be used for many other things.

I totally agree with you.
I hate code duplication

That exists and is called macro https://jinja.palletsprojects.com/en/3.1.x/templates/#macros

Outside of that, we have https://www.home-assistant.io/docs/automation/using_blueprints/ to reuse more things.

It is possible to define new jinja macros (but also filters) to extend the templating engine that can be used anywhere in home assistant templates?

However, the request - as I understand it - is about functions in yaml, similar to script definition.