<commit_before>'use strict';

var floor = Math.floor;

module.exports = function peakFinding(list, opts) {
	if(!Array.isArray(list)) {
		throw new TypeError('Expected an Array');
	}

	opts = opts || {};
	opts.highest = opts.highest || false;

	if(opts.highest) {
		return Math.max.apply(Math, list);
	}

	var len = list.length,
		firstIndex = 0,
		lastIndex = len - 1,
	    middleIndex = floor(len/2);

	while(firstIndex <= lastIndex) {
		middleIndex = floor((firstIndex + lastIndex) / 2);

		if(list[middleIndex] < list[middleIndex - 1]) {
			lastIndex = middleIndex - 1;
		} else if(list[middleIndex] < list[middleIndex + 1]) {
			firstIndex = middleIndex + 1;
		} else {
			return list[middleIndex];
		}
	}
};
<commit_msg>Implement 2D version<commit_after>'use strict';

var floor = Math.floor;

/**
 *
 * @param {Array} array - An array of number or a matrix (array of arrays)
 * @param {Object} opts
 * @param {Boolean} opts.highest - Whether to return the highest peak (only in one dimension version)
 * @param {Boolean} opts.twoDimension - Whether it is the two dimension version
 *
 * @returns {Number}
 */
module.exports = function peakFinding(array, opts) {
	if(!Array.isArray(array)) {
		throw new TypeError('Expected an Array');
	}

	opts = opts || {};
	opts.highest = opts.highest || false;
	opts.twoDimension = opts.twoDimension || false;

	if(opts.highest && !opts.twoDimension) {
		return Math.max.apply(Math, array);
	}

	var len = array.length,
		firstIndex = 0,
		lastIndex = len - 1,
	    middleIndex = floor(len/2);

	while(firstIndex <= lastIndex) {
		var currEl, leftEl, rightEl;

		middleIndex = floor((firstIndex + lastIndex) / 2);

		if(opts.twoDimension) {
			var max = array[0][middleIndex],
				rowIndex = 0;

			for(var i = 1; i < len; i++) {
				if(array[i][middleIndex] > max) {
					max = array[i][middleIndex];
					rowIndex = i;
				}
			}

			currEl  = array[rowIndex][middleIndex];
			leftEl  = array[rowIndex][middleIndex - 1];
			rightEl = array[rowIndex][middleIndex + 1];
		} else {
			currEl  = array[middleIndex];
			leftEl  = array[middleIndex - 1];
			rightEl = array[middleIndex + 1];
		}

		if(currEl < leftEl) {
			lastIndex = middleIndex - 1;
		} else if(currEl < rightEl) {
			firstIndex = middleIndex + 1;
		} else {
			return currEl;
		}
	}
};

{'fraction_non_alphanumeric': 0.14590592334494773, 'fraction_numerical': 0.009581881533101045, 'mean_word_length': 3.400383141762452, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 4, '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': '3471432', 'n_tokens_mistral': 894, 'n_tokens_neox': 783, 'n_words': 197}