/**
 *
 * @param {string} a
 * @param {string} b
 * @returns {number}
 */
export function compareStrings(a, b) {
    // null check
    if (a === null) {
        if (b === null) {
            return 0;
        } else {
            return 1;
        }
    } else if (b === null) {
        return -1;
    }

    // undefined check
    if (a === undefined) {
        if (b === undefined) {
            return 0;
        } else {
            return 1;
        }
    } else if (b === undefined) {
        return -1;
    }

    const n = a.length;

    const m = b.length;

    if (n > m) {
        return 1;
    } else if (n < m) {
        return -1;
    }

    for (let i = 0; i < n; i++) {
        const c0 = a.charCodeAt(i);
        const c1 = b.charCodeAt(i);

        const d = c0 - c1;

        if (d !== 0) {
            return d;
        }
    }

    return 0;
}
