4
Marl3x
4y

This actually exists in our code-base like this. I have no fucking clue what it does.

function combine(arg0: string, arg1: string): string {
return !arg0 ? arg1 : !arg1 ? arg0 : `${arg0} ${arg1}`;
}

Comments
  • 1
  • 1
    why? combining two values when there is a chance both of them is not valid is not a sign of good code ...
  • 1
    This is simple. Here’s the table:
    arg0 arg1 outcome
    00 undefined
    01 arg1
    10 arg0
    11 arg0 arg1
  • 1
    @uyouthe I could figure out what it does as well, but this is a function that lays there, without documentation or any context attached to it. It's just bad code, especially for such a simple thing.
  • 5
    Could have been Array.prototype.slice.call(arguments).join(' ') and it will work for an arbitrary amount of arguments and without the bug when the initial code can return undefined (I don’t care about typescript here, that code CAN return undefined)
  • 0
    @uyouthe
    00 case is the same as 01
  • 0
    @iiii no. In the initial code it will be instantly !arg0 so return arg1, in my code it will be just arg1
  • 0
    @uyouthe I meant the initial code. It will check only first one before returning second one without a check.
  • 0
    @iiii yes that’s why 00 is undefined and 01 is arg1, not the same
Add Comment