<commit_before>$.getJSON('/courts', function (allData) {
    var data = [].concat(allData.meilahti, allData.herttoniemi)
    var sameDates = _.groupBy(data, 'date')

    var list = []
    _.forEach(sameDates, function (times, isoDate) {
        list.push('<h4>' + new Date(isoDate).toDateString() + '</h4>')
        var sameTimes = _.groupBy(times, 'time')
        _.forEach(sameTimes, function (fields, isoTime) {
            list.push('<p><span class="time">' + isoTime + '</span>')
            list.push(fields.map(function (field) {
                return '<button type="button" class="btn btn-' +
                    (field.location === 'meilahti' ? 'primary' : 'success') +
                    ' btn-xs">' + field.field + '</button>'
            }).join(''))
            list.push('</p>')
        })
    })
    $('.schedule').html(list.join(''))
})
<commit_msg>Simplify code<commit_after>$.getJSON('/courts', function (allData) {
    var data = [].concat(allData.meilahti, allData.herttoniemi)
    var sameDates = _.map(_.groupBy(data, 'date'), objectToArray)

    $('.schedule').html(sameDates.map(function (obj) {
        var isoDate = obj.key
        var times = obj.val
        return '<h4>' + new Date(isoDate).toDateString() + '</h4>' +
        _.map(_.groupBy(times, 'time'), objectToArray).map(function (obj2) {
            var isoTime = obj2.key
            var fields = obj2.val
            return '<p><span class="time">' + isoTime + '</span>' +
            fields.map(function (field) {
                return '<button type="button" class="btn btn-' +
                    (field.location === 'meilahti' ? 'primary' : 'success') +
                    ' btn-xs">' + field.field + '</button>'
            }).join('')+'</p>'
        }).join('')
    }).join(''))
})


function objectToArray(val, key) { return { key: key, val:val}}
{'fraction_non_alphanumeric': 0.19414316702819956, 'fraction_numerical': 0.003796095444685466, 'mean_word_length': 2.300536672629696, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '3573589', 'n_tokens_mistral': 599, 'n_tokens_neox': 574, 'n_words': 115}