@visactor/vutils
Advanced tools
Comparing version 0.16.15 to 0.16.16
export declare function array<T>(arr?: T | T[]): T[]; | ||
export declare function last<T>(val: T | T[]): T | undefined; | ||
export declare const span: (arr: number[]) => number; | ||
export declare function maxInArray(arr: number[]): number | undefined; | ||
export declare function minInArray(arr: number[]): number | undefined; | ||
export declare const maxInArray: <T>(arr: T[], compareFn?: (a: T, b: T) => number) => T; | ||
export declare const minInArray: <T>(arr: T[], compareFn?: (a: T, b: T) => number) => T; | ||
export declare function arrayEqual(a: any, b: any): boolean; | ||
@@ -7,0 +7,0 @@ export declare function uniqArray<T>(arr: T | T[]): T | T[]; |
@@ -29,10 +29,28 @@ "use strict"; | ||
function maxInArray(arr) { | ||
if (arr && (0, isArray_1.default)(arr)) return arr.reduce(((prev, curr) => Math.max(prev, curr)), -1 / 0); | ||
} | ||
exports.span = span; | ||
function minInArray(arr) { | ||
if (arr && (0, isArray_1.default)(arr)) return arr.reduce(((prev, curr) => Math.min(prev, curr)), 1 / 0); | ||
} | ||
const maxInArray = (arr, compareFn) => { | ||
var _a; | ||
if (0 === arr.length) return; | ||
let max = arr[0]; | ||
for (let i = 1; i < arr.length; i++) { | ||
const value = arr[i]; | ||
(null !== (_a = null == compareFn ? void 0 : compareFn(value, max)) && void 0 !== _a ? _a : value - max > 0) && (max = value); | ||
} | ||
return max; | ||
}; | ||
exports.maxInArray = maxInArray; | ||
const minInArray = (arr, compareFn) => { | ||
var _a; | ||
if (0 === arr.length) return; | ||
let min = arr[0]; | ||
for (let i = 1; i < arr.length; i++) { | ||
const value = arr[i]; | ||
(null !== (_a = null == compareFn ? void 0 : compareFn(value, min)) && void 0 !== _a ? _a : value - min < 0) && (min = value); | ||
} | ||
return min; | ||
}; | ||
function arrayEqual(a, b) { | ||
@@ -62,5 +80,4 @@ if (!(0, isArray_1.default)(a) || !(0, isArray_1.default)(b)) return !1; | ||
exports.span = span, exports.maxInArray = maxInArray, exports.minInArray = minInArray, | ||
exports.arrayEqual = arrayEqual, exports.uniqArray = uniqArray, exports.shuffleArray = shuffleArray, | ||
exports.flattenArray = flattenArray; | ||
exports.minInArray = minInArray, exports.arrayEqual = arrayEqual, exports.uniqArray = uniqArray, | ||
exports.shuffleArray = shuffleArray, exports.flattenArray = flattenArray; | ||
//# sourceMappingURL=array.js.map |
export declare function array<T>(arr?: T | T[]): T[]; | ||
export declare function last<T>(val: T | T[]): T | undefined; | ||
export declare const span: (arr: number[]) => number; | ||
export declare function maxInArray(arr: number[]): number | undefined; | ||
export declare function minInArray(arr: number[]): number | undefined; | ||
export declare const maxInArray: <T>(arr: T[], compareFn?: (a: T, b: T) => number) => T; | ||
export declare const minInArray: <T>(arr: T[], compareFn?: (a: T, b: T) => number) => T; | ||
export declare function arrayEqual(a: any, b: any): boolean; | ||
@@ -7,0 +7,0 @@ export declare function uniqArray<T>(arr: T | T[]): T | T[]; |
@@ -19,9 +19,23 @@ import isArray from "./isArray"; | ||
export function maxInArray(arr) { | ||
if (arr && isArray(arr)) return arr.reduce(((prev, curr) => Math.max(prev, curr)), -1 / 0); | ||
} | ||
export const maxInArray = (arr, compareFn) => { | ||
var _a; | ||
if (0 === arr.length) return; | ||
let max = arr[0]; | ||
for (let i = 1; i < arr.length; i++) { | ||
const value = arr[i]; | ||
(null !== (_a = null == compareFn ? void 0 : compareFn(value, max)) && void 0 !== _a ? _a : value - max > 0) && (max = value); | ||
} | ||
return max; | ||
}; | ||
export function minInArray(arr) { | ||
if (arr && isArray(arr)) return arr.reduce(((prev, curr) => Math.min(prev, curr)), 1 / 0); | ||
} | ||
export const minInArray = (arr, compareFn) => { | ||
var _a; | ||
if (0 === arr.length) return; | ||
let min = arr[0]; | ||
for (let i = 1; i < arr.length; i++) { | ||
const value = arr[i]; | ||
(null !== (_a = null == compareFn ? void 0 : compareFn(value, min)) && void 0 !== _a ? _a : value - min < 0) && (min = value); | ||
} | ||
return min; | ||
}; | ||
@@ -28,0 +42,0 @@ export function arrayEqual(a, b) { |
{ | ||
"name": "@visactor/vutils", | ||
"version": "0.16.15", | ||
"version": "0.16.16", | ||
"main": "cjs/index.js", | ||
@@ -31,5 +31,5 @@ "module": "es/index.js", | ||
"@internal/bundler": "0.0.1", | ||
"@internal/eslint-config": "0.0.1", | ||
"@internal/ts-config": "0.0.1", | ||
"@internal/jest-config": "0.0.1" | ||
"@internal/jest-config": "0.0.1", | ||
"@internal/eslint-config": "0.0.1" | ||
}, | ||
@@ -36,0 +36,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1417065
13977