<commit_before>import {List, Map} from 'immutable';

export function setEntries(state, entries) {
    return state.set('entries', List(entries));
}

function getWinners(vote) {
    if (!vote) return [];
    const [a, b] = vote.get('pair');
    const aVotes = vote.getIn(['tally', a], 0);
    const bVotes = vote.getIn(['tally', b], 0);
    if      (aVotes > bVotes) return [a];
    else if (aVotes < bVotes) return [b];
    else                      return [a, b];
}

export function next(state) {
    const entries = state.get('entries')
        .concat(getWinners(state.get('vote')));
    return state.merge({
        vote: Map({pair: entries.take(2)}),
        entries: entries.skip(2)
    });
}

export function vote(state, entry) {
    return state.updateIn(
        ['vote', 'tally', entry],
        0,<commit_msg>added ending vote logic to next()<commit_after>import {List, Map} from 'immutable';

export function setEntries(state, entries) {
    return state.set('entries', List(entries));
}

function getWinners(vote) {
    if (!vote) return [];
    const [a, b] = vote.get('pair');
    const aVotes = vote.getIn(['tally', a], 0);
    const bVotes = vote.getIn(['tally', b], 0);
    if      (aVotes > bVotes) return [a];
    else if (aVotes < bVotes) return [b];
    else                      return [a, b];
}

export function next(state) {
    const entries = state.get('entries')
        .concat(getWinners(state.get('vote')));
    if (entries.size === 1) {
        return state.remove('vote')
                    .remove('entries')
                    .set('winner', entries.first());
    } else {
        return state.merge({
            vote: Map({pair: entries.take(2)}),
            entries: entries.skip(2)
        });
    }
}

// export function next(state) {
//     const entries = state.get('entries')
//         .concat(getWinners(state.get('vote')));
//     if (entries.size === 1) {
//         return state.remove('vote')
//             .remove('entries')
//             .set('winner', entries.first());
//     } else {
//         return state.merge({
//             vote: Map({pair: entries.take(2)}),
//             entries: entries.skip(2)
//         });
//     }
// }

export function vote(state, entry) {
    return state.updateIn(
        ['vote', 'tally', entry],
        0,
{'fraction_non_alphanumeric': 0.17664930555555555, 'fraction_numerical': 0.006076388888888889, 'mean_word_length': 2.2510578279266573, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3039944', 'n_tokens_mistral': 738, 'n_tokens_neox': 729, 'n_words': 176}