@tldraw/utils
Advanced tools
Comparing version 3.7.0-canary.9aeff86e695c to 3.7.0-canary.a0088a0d6a77
@@ -339,2 +339,4 @@ import { default as throttle } from 'lodash.throttle'; | ||
/* Excluded from this release type: maxBy */ | ||
/* Excluded from this release type: measureAverageDuration */ | ||
@@ -341,0 +343,0 @@ |
@@ -88,2 +88,3 @@ "use strict"; | ||
mapObjectMapValues: () => import_object.mapObjectMapValues, | ||
maxBy: () => import_array.maxBy, | ||
measureAverageDuration: () => import_perf.measureAverageDuration, | ||
@@ -160,5 +161,5 @@ measureCbDuration: () => import_perf.measureCbDuration, | ||
"@tldraw/utils", | ||
"3.7.0-canary.9aeff86e695c", | ||
"3.7.0-canary.a0088a0d6a77", | ||
"cjs" | ||
); | ||
//# sourceMappingURL=index.js.map |
@@ -25,2 +25,3 @@ "use strict"; | ||
last: () => last, | ||
maxBy: () => maxBy, | ||
minBy: () => minBy, | ||
@@ -64,2 +65,14 @@ partition: () => partition, | ||
} | ||
function maxBy(arr, fn) { | ||
let max; | ||
let maxVal = -Infinity; | ||
for (const item of arr) { | ||
const val = fn(item); | ||
if (val > maxVal) { | ||
max = item; | ||
maxVal = val; | ||
} | ||
} | ||
return max; | ||
} | ||
function partition(arr, predicate) { | ||
@@ -66,0 +79,0 @@ const satisfies = []; |
@@ -52,3 +52,6 @@ "use strict"; | ||
} | ||
close() { | ||
this.queue = []; | ||
} | ||
} | ||
//# sourceMappingURL=ExecutionQueue.js.map |
{ | ||
"name": "@tldraw/utils", | ||
"description": "A tiny little drawing app (private utilities).", | ||
"version": "3.7.0-canary.9aeff86e695c", | ||
"version": "3.7.0-canary.a0088a0d6a77", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "tldraw Inc.", |
@@ -12,2 +12,3 @@ import { registerTldrawLibraryVersion } from './lib/version' | ||
last, | ||
maxBy, | ||
minBy, | ||
@@ -14,0 +15,0 @@ partition, |
@@ -52,2 +52,16 @@ /** | ||
/** @internal */ | ||
export function maxBy<T>(arr: readonly T[], fn: (item: T) => number): T | undefined { | ||
let max: T | undefined | ||
let maxVal: number = -Infinity | ||
for (const item of arr) { | ||
const val = fn(item) | ||
if (val > maxVal) { | ||
max = item | ||
maxVal = val | ||
} | ||
} | ||
return max | ||
} | ||
/** | ||
@@ -54,0 +68,0 @@ * Partitions an array into two arrays, one with items that satisfy the predicate, and one with |
@@ -34,2 +34,6 @@ import { sleep } from './control' | ||
} | ||
close() { | ||
this.queue = [] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
531545
7968