<commit_before>var identity = require("./identity.js")
var isFunction = require("./is-function.js")
var map = require("./map.js")
var pluck = require("./pluck.js")

module.exports = sortBy

function sortBy(obj, value, context) {
    var iterator = value == null ? identity : lookupIterator(value)

    return pluck(map(obj, function(value, index, list) {
        return {
            value: value,
            index: index,
            criteria: iterator.call(context, value, index, list)
        }
    }).sort(function (left, right) {
        var a = left.criteria
        var b = right.criteria

        if (a !== b) {
            if (a > b || a === void 0) {
                return 1
            }

            if (a < b || b === void 0) {
                return -1
            }
        }
        return left.index - right.index;
    }), "value")
}

function lookupIterator(value) {
    return isFunction(value) ? value : function (obj) {
        return obj[value]
    }
}<commit_msg>update lookup iterator in sortBy function<commit_after>var identity = require("./identity.js")
var isFunction = require("./is-function.js")
var map = require("./map.js")
var pluck = require("./pluck.js")
var property = require("./property.js")

module.exports = sortBy

function sortBy(obj, iterator, context) {
    iterator = lookupIterator(iterator)

    return pluck(map(obj, function(value, index, list) {
        return {
            value: value,
            index: index,
            criteria: iterator.call(context, value, index, list)
        }
    }).sort(function (left, right) {
        var a = left.criteria
        var b = right.criteria

        if (a !== b) {
            if (a > b || a === void 0) {
                return 1
            }

            if (a < b || b === void 0) {
                return -1
            }
        }
        return left.index - right.index
    }), "value")
}

function lookupIterator(value) {
    if (value == null) {
        return identity
    }

    if (isFunction(value)) {
        return value
    }

    return property(value)
}
{'fraction_non_alphanumeric': 0.13478260869565217, 'fraction_numerical': 0.003864734299516908, 'mean_word_length': 1.8331053351573188, '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': '5844861', 'n_tokens_mistral': 618, 'n_tokens_neox': 600, 'n_words': 168}