<commit_before>// adopted from: sort-array <https://github.com/75lb/sort-array>
// Copyright (c) 2015 <NAME> <<EMAIL>> (MIT)

// sort an array of objects by any number of fields, in any order
// this function assumes a flat object structure for the items
// in the array.

var rest = require('../function/rest')
var kindOf = require('../lang/kindOf')

function sortBy (data) {
  return rest(function (args) {
    if (kindOf(args[args.length - 1]) === 'object') {
      var customOrder = args.pop()
    }

    var columns = [].concat(args)
    return data.sort(sortByFunc(columns, customOrder))
  })

  function sortByFunc (properties, customOrder) {
    var props = properties.slice(0)
    var property = props.shift()

    return function tryIt (a, b) {
      var result
      var x = a[property]
      var y = b[property]

      if (typeof x === 'undefined' && typeof y !== 'undefined') result = -1
      else if (typeof x !== 'undefined' && typeof y === 'undefined') result = 1
      else if (typeof x === 'undefined' && typeof y === 'undefined') result = 0
      else if (customOrder && customOrder[property]) {
        result = customOrder[property].indexOf(x) - customOrder[property].indexOf(y)
      } else {
        result = x < y ? -1 : x > y ? 1 : 0
      }

      if (result === 0) {
        if (props.length) {
          property = props.shift()
          return tryIt(a, b)
        } else {
          return 0
        }
      } else {
        props = properties.slice(0)
        property = props.shift()
        return result
      }

      return 0
    }
  }
}

module.exports = sortBy
<commit_msg>lint array/sortByAny — removed unreached return<commit_after>// adopted from: sort-array <https://github.com/75lb/sort-array>
// Copyright (c) 2015 <NAME> <<EMAIL>> (MIT)

// sort an array of objects by any number of fields, in any order
// this function assumes a flat object structure for the items
// in the array.

var rest = require('../function/rest')
var kindOf = require('../lang/kindOf')

function sortBy (data) {
  return rest(function (args) {
    if (kindOf(args[args.length - 1]) === 'object') {
      var customOrder = args.pop()
    }

    var columns = [].concat(args)
    return data.sort(sortByFunc(columns, customOrder))
  })

  function sortByFunc (properties, customOrder) {
    var props = properties.slice(0)
    var property = props.shift()

    return function tryIt (a, b) {
      var result
      var x = a[property]
      var y = b[property]

      if (typeof x === 'undefined' && typeof y !== 'undefined') result = -1
      else if (typeof x !== 'undefined' && typeof y === 'undefined') result = 1
      else if (typeof x === 'undefined' && typeof y === 'undefined') result = 0
      else if (customOrder && customOrder[property]) {
        result = customOrder[property].indexOf(x) - customOrder[property].indexOf(y)
      } else {
        result = x < y ? -1 : x > y ? 1 : 0
      }

      if (result === 0) {
        if (props.length) {
          property = props.shift()
          return tryIt(a, b)
        } else {
          return 0
        }
      } else {
        props = properties.slice(0)
        property = props.shift()
        return result
      }
    }
  }
}

module.exports = sortBy

{'fraction_non_alphanumeric': 0.14127082048118444, 'fraction_numerical': 0.0107958050586058, 'mean_word_length': 2.3295687885010268, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '3477813', 'n_tokens_mistral': 1003, 'n_tokens_neox': 967, 'n_words': 311}