function extent(values, valueof) {
	if (!Array.isArray(values)) throw new TypeError('Cannot calculate extent of non-array value.');
	let min;
	let max;
	if (valueof === undefined) {
		for (const value of values) {
			if (typeof value !== 'number') continue;

			if (min === undefined) {
				if (value >= value) min = max = value;
			} else {
				if (min > value) min = value;
				if (max < value) max = value;
			}
		}
	} else {
		let index = -1;
		for (let value of values) {
			if (typeof value !== 'number') continue;
			if ((value = valueof(value, ++index, values)) != null) {
				if (min === undefined) {
					if (value >= value) min = max = value;
				} else {
					if (min > value) min = value;
					if (max < value) max = value;
				}
			}
		}
	}
	return [min, max];
}
This function is used to find the minimum and maximum values in an array.

@param {Array} values - An array from which min and max values should be determined.
@param {Function} [valueof] - An optional function that defines how to obtain the measuring value.
@return {Array} An array containing the minimum and maximum of numbers, respectively.