do sorting before we parse
178373
function reducer(individualSeries, initialFunction, reductionFunction) {
                        if (individualSeries.length == 0) {
                            return NaN;
                        }
                        var initial = initialFunction(individualSeries[0][1]);
                        var i=1;
                        for (; initial==null && i<individualSeries.length; i++) {
                            initial = initialFunction(individualSeries[i][1]);
                        }
                        for (; i<individualSeries.length; i++) {
                            if (individualSeries[i][1] != null) {
                                initial = reductionFunction(initial, individualSeries[i][1]);
                            }
                        }
                        return initial;
                    }
1220506
def ordered(self, ord='desc'):
        """"""
        if ord not in ('asc', 'desc', ):
            raise
        ord_f = getattr(PIDRelation.index, ord)()
        return self.order_by(ord_f)
815587
def sort_nicely(l):
    """"""
    convert = lambda text: int(text) if text.isdigit() else text
    alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
    l.sort(key=alphanum_key)
795642
def sort_entries(self):
        """"""
        return sorted(self.data, key=self.sort_func, reverse=self.get_reverse())
505336
protected function _sort()
        {
            if ($this->_dirtyIndex) {
                $newIndex = array();
                $index = 0;

                foreach ($this->_pages as $hash => $page) {
                    $order = $page->getOrder();
                    if ($order === null) {
                        $newIndex[$hash] = $index;
                        $index++;
                    } else {
                        $newIndex[$hash] = $order;
                    }
                }

                asort($newIndex);

                $this->_index = $newIndex;
                $this->_dirtyIndex = false;
            }
        }
327306
function _convertSortPref(sortMethod) {
        if (!sortMethod) {
            return null;
        }

        if (_sortPrefConversionMap.hasOwnProperty(sortMethod)) {
            sortMethod = _sortPrefConversionMap[sortMethod];
            PreferencesManager.setViewState(_WORKING_SET_SORT_PREF, sortMethod);
        } else {
            sortMethod = null;
        }

        return sortMethod;
    }
1065873
private static String quoteSort(Sort[] sort) {
        LinkedList<String> sorts = new LinkedList<String>();
        for (Sort pair : sort) {
            sorts.add(String.format("{%s: %s}", Helpers.quote(pair.getName()), Helpers.quote(pair.getOrder().toString())));
        }
        return sorts.toString();
    }
863120
def _parse_and_sort_accept_header(accept_header):
    
    return sorted([_split_into_mimetype_and_priority(x) for x in accept_header.split(',')],
                  key=lambda x: x[1], reverse=True)
692111
def _order(self, value, is_reverse=None):
        

        def _dict_parser(dict_doc):
            """ dict ordered by:
            valueType_N -> key_N -> value_N
            """
            result = list()
            for key in dict_doc:
                data = self._order(dict_doc[key])
                res = (data[0], key, data[1])
                result.append(res)
            return tuple(result)

        def _list_parser(list_doc):
            """list will iter members to compare
            """
            result = list()
            for member in list_doc:
                result.append(self._order(member))
            return result

        # (TODO) include more data type
        if value is None or not isinstance(value, (dict,
                                                   list,
                                                   basestring,
                                                   bool,
                                                   float,
                                                   int)):
            # not support/sortable value type
            value = (0, None)

        elif isinstance(value, bool):
            value = (5, value)

        elif isinstance(value, (int, float)):
            value = (1, value)

        elif isinstance(value, basestring):
            value = (2, value)

        elif isinstance(value, dict):
            value = (3, _dict_parser(value))

        elif isinstance(value, list):
            if len(value) == 0:
                # [] less then None
                value = [(-1, [])]
            else:
                value = _list_parser(value)

            if is_reverse is not None:
                # list will firstly compare with other doc by it's smallest
                # or largest member
                value = max(value) if is_reverse else min(value)
            else:
                # if the smallest or largest member is a list
                # then compaer with it's sub-member in list index order
                value = (4, tuple(value))

        return value
534936
def sort(input, property = nil, nils = "first")
      raise ArgumentError, "Cannot sort a null object." if input.nil?

      if property.nil?
        input.sort
      else
        if nils == "first"
          order = - 1
        elsif nils == "last"
          order = + 1
        else
          raise ArgumentError, "Invalid nils order: " \
            "'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
        end

        sort_input(input, property, order)
      end
    end
1160254
def _sort_by_sortedset_before(self):
        
        return self._sort_by_sortedset and self._sort_limits and (not self._lazy_collection['pks']
                                                            or self._want_score_value)
673903
function sortByOrdinal(extensions, done) {
    const sorted = extensions.sort((a, b) => {
        if (a.ordinal || b.ordinal) {
            if (!a.ordinal) return 1;
            if (!b.ordinal) return -1;
            if (a.ordinal < b.ordinal) return -1;
            return 1;
        }
        return a.pluginId.localeCompare(b.pluginId);
    });

    if (done) {
        done(sorted);
    }

    return sorted;
}
599049
def _process_and_sort(s, force_ascii, full_process=True):
    """"""
    # pull tokens
    ts = utils.full_process(s, force_ascii=force_ascii) if full_process else s
    tokens = ts.split()

    # sort tokens and join
    sorted_string = u" ".join(sorted(tokens))
    return sorted_string.strip()
337030
function parseOrders(field, fieldName, model) {
		var orders = field.order;
		if (!orders) return;
		if (!Array.isArray(orders)) orders = field.order = [orders];

		_.forEach(orders, function(order, index) {
			// if just a string, leave alone - is raw query
			if (_.isString(order)) return;

			// if an object (e.g. {raw: ...}), add 'ASC' sort order
			if (!Array.isArray(order)) {
				orders[index] = [order, 'ASC'];
				return;
			}

			// add 'ASC' sort order if no sort order defined
			if (order.length == 0) throw new Sequelize.VirtualFieldsError("Invalid virtual field order in '" + model.name + "'.'" + fieldName + "'");
			if (order.length == 1) {
				order[1] = 'ASC';
			} else {
				// ensure direction is ASC or DESC
				if (['ASC', 'DESC'].indexOf(order[order.length - 1].toUpperCase()) == -1) {
					order.push('ASC');
				} else {
					order[order.length - 1] = order[order.length - 1].toUpperCase();
				}
			}

			// make preceeding models into {model: model} form
			var parent = model;
			for (var i = 0; i < order.length - 2; i++) {
				parseClause(order, i, 'Order', model.name, fieldName, parent);
				parent = order[i].model;
			}

			// check attribute is valid
			var attribute = order[order.length - 2];
			if (_.isString(attribute) && !parent.attributes[attribute]) throw new Sequelize.VirtualFieldsError("Order of virtual field '" + model.name + "'.'" + fieldName + "' refers to a nonexistent field '" + parent.name + "'.'" + attribute + "'");
		});
	}
1116666
def _parse_info(self, info_str, num_alts):
        """"""
        result = OrderedDict()
        if info_str == ".":
            return result
        # The standard is very nice to parsers, we can simply split at
        # semicolon characters, although I (Manuel) don't know how strict
        # programs follow this
        for entry in info_str.split(";"):
            if "=" not in entry:  # flag
                key = entry
                result[key] = parse_field_value(self.header.get_info_field_info(key), True)
            else:
                key, value = split_mapping(entry)
                result[key] = parse_field_value(self.header.get_info_field_info(key), value)
            self._info_checker.run(key, result[key], num_alts)
        return result
30126
function(data, sortOrder) {
  if(sortOrder){
    data = _.sortBy(data, sortOrder.substr(1));
    if(sortOrder[0] === '-'){
      data.reverse();
    }
  }
  return data;
}
156829
def sort_by(self, property, order="asc"):
        
        self.__prepare()
        if isinstance(self._json_data, list):
            if order == "asc":
                self._json_data = sorted(
                    self._json_data,
                    key=lambda x: x.get(property)
                )
            else:
                self._json_data = sorted(
                    self._json_data,
                    key=lambda x: x.get(property),
                    reverse=True
                )

        return self