<commit_before>
exports.sort = function (Handlebars) {
	return function (array, field, options) {
		if (arguments.length === 1) {
			throw new Error('Handlebars Helper "sort" needs 1 parameter');
		}

		options = arguments[arguments.length - 1];

		if (arguments.length === 2) {
			field = undefined;
		}

		var results;
		if (field === undefined) {
			results = array.sort();
		} else {
			results = array.sort(function (a, b) {
				return a[field] > b[field];
			});
		}

		if (!options.fn) {
			return results;
		} else {
			if (results.length) {
				var data = Handlebars.createFrame(options.data);
				return results.map(function (result, i) {
					data.index = i;
					data.first = (i === 0);
					data.last  = (i === results.length - 1);
					return options.fn(result, {data: data});
				}).join('');
			} else {
				return options.inverse(this);<commit_msg>Sort by key now confirms both inputs are objects before comparing keys.<commit_after>
exports.sort = function (Handlebars) {
	return function (input, key, options) {
		if (arguments.length === 1) {
			throw new Error('Handlebars Helper "sort" needs 1 parameter');
		}

		options = arguments[arguments.length - 1];

		if (arguments.length === 2) {
			key = undefined;
		}

		var results = input.concat();
		if (key === undefined) {
			results.sort();
		} else {
			results.sort(function (a, b) {
				if (typeof a !== 'object' && typeof b !== 'object') return 0;
				if (typeof a !== 'object') return -1;
				if (typeof b !== 'object') return 1;
				return a[key] > b[key];
			});
		}

		if (!options.fn) {
			return results;
		} else {
			if (results.length) {
				var data = Handlebars.createFrame(options.data);
				return results.map(function (result, i) {
					data.index = i;
					data.first = (i === 0);
					data.last  = (i === results.length - 1);
					return options.fn(result, {data: data});
				}).join('');
			} else {
				return options.inverse(this);
{'fraction_non_alphanumeric': 0.1654564315352697, 'fraction_numerical': 0.007780082987551867, 'mean_word_length': 2.9127789046653145, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7462595', 'n_tokens_mistral': 770, 'n_tokens_neox': 618, 'n_words': 178}