<commit_before>function threadIdFor(message) {
    const recipienList = message.recipients || [];

    return recipienList.concat(message.sender).
        filter(character => character).
        map(character => character.id).
        sort().
        join("-");
}

function threadMessages(messageList) {
    const threads = {};

    messageList.forEach(message => {
        const threadId = threadIdFor(message);

        threads[threadId] = threads[threadId] || [];
        threads[threadId].push(message);
    });

    return Object.keys(threads).
        map(threadId => threads[threadId]).
        sort((a, b) => {
            const lastTimestampA = a[a.length - 1].sentAt;
            const lastTimestampB = b[b.length - 1].sentAt;

            return parseInt(lastTimestampA.replace(/[^0-9]/g, ''), 10) -
                parseInt(lastTimestampB.replace(/[^0-9]/g, ''), 10);
        }).
        map(messageGroup => {
            const randomMessage = messageGroup[0];
            const recipients = randomMessage.recipients || [];
            if (randomMessage.sender) {
                recipients.push(randomMessage.sender);
            }

            return {<commit_msg>Make threadMessages function easier to import<commit_after>function threadIdFor(message) {
    const recipienList = message.recipients || [];

    return recipienList.concat(message.sender).
        filter(character => character).
        map(character => character.id).
        sort().
        join("-");
}

export function threadMessages(messageList) {
    const threads = {};

    messageList.forEach(message => {
        const threadId = threadIdFor(message);

        threads[threadId] = threads[threadId] || [];
        threads[threadId].push(message);
    });

    return Object.keys(threads).
        map(threadId => threads[threadId]).
        sort((a, b) => {
            const lastTimestampA = a[a.length - 1].sentAt;
            const lastTimestampB = b[b.length - 1].sentAt;

            return parseInt(lastTimestampA.replace(/[^0-9]/g, ''), 10) -
                parseInt(lastTimestampB.replace(/[^0-9]/g, ''), 10);
        }).
        map(messageGroup => {
            const randomMessage = messageGroup[0];
            const recipients = randomMessage.recipients || [];
            if (randomMessage.sender) {
                recipients.push(randomMessage.sender);
            }

            return {
{'fraction_non_alphanumeric': 0.1394572025052192, 'fraction_numerical': 0.00918580375782881, 'mean_word_length': 2.198931909212283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5297494', 'n_tokens_mistral': 670, 'n_tokens_neox': 637, 'n_words': 114}