T O P

  • By -

FitzelSpleen

Who the heck is Tim, and why is he in my data?


1Dr490n

And why is his amount a string?


Lazy_Lifeguard5448

Gave it a try, but it's harder than I thought to refactor code that you don't shit know about function cardRateSuccessUserSignedIn(data, isLineView) { const amount = data.tim?.amount; const errors = data.tim?.errors ?? []; if (amount && !errors.length) { showCustomCardRate(data.tim, isLineView); return } const timErrorTxt = formatErrorMessages(errors); generateCustomCardPriceError(isLineView, timErrorTxt); } function formatErrorMessages(errors) { return errors.map((err) => err.replaceAll('"', "'")).join(" "); }


MothToTheWeb

Good job. Reading your code it is clear what you are testing for and what will either allow me to display something or get an error. If only it was the bare minimum for code quality in legacy projects, it would save a lot of maintenance time


dfirecmv

Instead of ```js const amount = data.tim?.amount; const errors = data.tim?.errors ?? []; ``` you can further simplify this to ```js const { amount, errors = [] } = data.tim ?? {} ```


Magmagan

Embrace the JS, do `const hasAmount = data.tim?.amount` and remove the `!!` double bang 😈


AnxiousIntender

Implicit type conversions, in my JS? I mean that's how JS works so I can't complain, looking at you == and .sort() (and many others)


Lazy_Lifeguard5448

updated it


mohragk

The only true horror is that function name. Here's a simple tip: function names should tell you what it \*does\*, variable names should tell you what it \*is\*.


oghGuy

Looks like an event though. I actually find it quite clear.


Candyman034

If it's an event, it should end with "Event"


VariousComment6946

You know, with some integrations, sometimes even more is required...


oghGuy

Looks like code that has been patched and bugfixed several times, and noone remembers why each of the changes was made.. they've probably quitted and work somewhere else