ed on their order.
            if (indexA !== undefined && indexB !== undefined) {
                return indexA - indexB;
            }

            // If only one of the keys exists in orderedKeys, move it to the front.
            if (indexA !== undefined) {
                return -1;
            } else if (indexB !== undefined) {
                return 1;
            }

            // If neither key is in orderedKeys, sort alphabetically so we have predictable ordering.
            return a.localeCompar