<commit_before>/**
 * primaryEmail takes the given email addresses and returns the email address
 * marked as 'Primary'.
 * If none exists it returns the first active email address.
 *
 * @param emailAddresses {Array}: Array containing the email addresses.
 *
 * @returns email_address {String}: The primary email address.
 */
angular.module('app.filters').filter('primaryEmail', primaryEmail);

primaryEmail.$inject = ['$filter'];
function primaryEmail($filter) {
    return function(emailAddresses) {
        var primaryEmailAddress = '';

        if (emailAddresses && emailAddresses.length) {
            primaryEmailAddress = $filter('filter')(emailAddresses, {status: 2})[0];

            if (!primaryEmailAddress) {
                // No primary email set, so just get the first active email address.
                primaryEmailAddress = $filter('filter')(emailAddresses, {status: '!' + 0})[0];
            }

            primaryEmailAddress = primaryEmailAddress.email_address;
        }

        return primaryEmailAddress;
    };
}
<commit_msg>Improved/fixed primaryEmail filter<commit_after>/**
 * primaryEmail takes the given email addresses and returns the email address
 * marked as 'Primary'.
 * If none exists it returns the first active email address.
 *
 * @param emailAddresses {Array}: Array containing the email addresses.
 *
 * @returns email_address {String}: The primary email address.
 */
angular.module('app.filters').filter('primaryEmail', primaryEmail);

primaryEmail.$inject = ['$filter'];
function primaryEmail($filter) {
    return function(emailAddresses) {
        var primaryEmailAddress = '';
        var filteredEmailAddresses = $filter('filter')(emailAddresses, {status: '!' + 0});

        if (filteredEmailAddresses && filteredEmailAddresses.length) {
            primaryEmailAddress = $filter('filter')(filteredEmailAddresses, {status: 2})[0];

            if (!primaryEmailAddress) {
                // No primary email set, so just get the first active email address.
                primaryEmailAddress = filteredEmailAddresses[0];
            }

            primaryEmailAddress = primaryEmailAddress.email_address;
        }

        return primaryEmailAddress;
    };
}

{'fraction_non_alphanumeric': 0.10875451263537907, 'fraction_numerical': 0.0036101083032490976, 'mean_word_length': 3.2471264367816093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6122406', 'n_tokens_mistral': 559, 'n_tokens_neox': 539, 'n_words': 163}