You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
import { isAnyArray } from 'is-any-array';
|
|
|
|
function min(input) {
|
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
|
|
if (!isAnyArray(input)) {
|
|
throw new TypeError('input must be an array');
|
|
}
|
|
|
|
if (input.length === 0) {
|
|
throw new TypeError('input must not be empty');
|
|
}
|
|
|
|
var _options$fromIndex = options.fromIndex,
|
|
fromIndex = _options$fromIndex === void 0 ? 0 : _options$fromIndex,
|
|
_options$toIndex = options.toIndex,
|
|
toIndex = _options$toIndex === void 0 ? input.length : _options$toIndex;
|
|
|
|
if (fromIndex < 0 || fromIndex >= input.length || !Number.isInteger(fromIndex)) {
|
|
throw new Error('fromIndex must be a positive integer smaller than length');
|
|
}
|
|
|
|
if (toIndex <= fromIndex || toIndex > input.length || !Number.isInteger(toIndex)) {
|
|
throw new Error('toIndex must be an integer greater than fromIndex and at most equal to length');
|
|
}
|
|
|
|
var minValue = input[fromIndex];
|
|
|
|
for (var i = fromIndex + 1; i < toIndex; i++) {
|
|
if (input[i] < minValue) minValue = input[i];
|
|
}
|
|
|
|
return minValue;
|
|
}
|
|
|
|
export { min as default };
|
|
|