"use strict";

exports.__esModule = true;
exports.dynamicSort = void 0;

/**
 * ---
 *  对象数组动态排序
 * @param {*} property 对象key值
 * @param sortOrder 1正序，-1倒序
 * @static
 * @returns {boolean}
 * @author libo
 * @function dynamicSort
 * @example  01 对象数组排序
 * --------------------------------------------------------------------------
 *  import { dynamicSort } from "@riil-frontend/utils";
 *  var People = [
 *      {Name: "Name", Surname: "Surname"},
 *      {Name:"AAA", Surname:"ZZZ"},
 *      {Name: "Name", Surname: "AAA"}
 *  ];
 *
 *  People.sort(dynamicSort("Name"));
 *  People.sort(dynamicSort("Surname"));
 *  People.sort(dynamicSort("Surname",-1));//倒序
 *
 */
var dynamicSort = function dynamicSort(property) {
  var sortOrder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  return function (a, b) {
    var result = a[property] < b[property] ? -1 : a[property] > b[property] ? 1 : 0;
    return result * sortOrder;
  };
};

exports.dynamicSort = dynamicSort;