Thursday, November 13, 2025

Pick a property name already!

     const getLast4 = (c: any): string | undefined =>

        {
            if (c?.lastFourDigitsAccountNum && /^\d{4}$/.test(String(c.lastFourDigitsAccountNum)))
            {
                return String(c.lastFourDigitsAccountNum);
            }
            let v =
                c?.lastFourDigits ??
                c?.lastFour ??
                c?.last4 ??
                c?.cardLast4 ??
                c?.accountLast4 ??
                c?.last_digits ??
                c?.lastDigits ??
                undefined;

            if (!v || String(v).trim() === "")
            {
                const cand = [
                    c?.cardNumber,
                    c?.pan,
                    c?.maskedPan,
                    c?.maskedCard,
                    c?.accountNumber,
                    c?.maskedAccount,
                ].filter(Boolean);

                for (const s of cand)
                {
                    const m = String(s).match(/(\d{4})\D*$/);
                    if (m) { v = m[1]; break; }
                }
            }
            return v && /^\d{4}$/.test(String(v)) ? String(v) : undefined;
        };

Thursday, April 24, 2025

What the ELSE?

public SessionStateChangeResult StateChangeFlag
{
    get
    {
        if ( this.HasDeletedSession )
        {
            return SessionStateChangeResult.SourceMerged;
        }
        else
        {
            if ( this.HasMovedSession )
            {
                return SessionStateChangeResult.SourceMoved;
            }
            else
            {
                if ( this.HasNewSession )
                {
                    return SessionStateChangeResult.SourceUpdateNewDest;
                }
                else
                {
                    if ( this.HasUpdates )
                    {
                        return SessionStateChangeResult.SourceUpdateDestUpdate;
                    }
                    else
                    {
                        return SessionStateChangeResult.Invalid;
                    }
                }
            }
        }
    }
}

Wednesday, May 25, 2022

Logic = hard

 d.results.length > 0 ? this.existingAddresses = true : this.existingAddresses = false

Thursday, May 19, 2022

Variable abuse

let checkForHighlight = true;

for (let rows of this.tableBody.nativeElement.children)
{
    if (checkForHighlight && rows.classList.contains('alert-warning'))
    {
        checkForHighlight = false;
    }
}

if (!checkForHighlight)
{
    this.showQuantityWarning = true;
}
else
{
    this.showQuantityWarning = false;
}

Friday, September 4, 2020

Friday, March 1, 2019

What's a bool?

If ValidAccess = False Then
    ...
ElseIf ValidAccess = True Then
    ...
End If

Friday, January 18, 2019

Why! Why! Why!

public override bool Validate()
{
    bool bValidate = false;

    try
    {
        bValidate = (EOID > 0 ? true : false);
    }
    catch (Exception ex)
    {
        Utilities.LogError(ex.Message, "AbsentHoursBL");
        throw;
    }

    return bValidate;
}