@tldraw/utils
Advanced tools
Comparing version 3.7.0-canary.84653f8a3c53 to 3.7.0-canary.8e16c48b63b1
@@ -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.84653f8a3c53", | ||
"3.7.0-canary.8e16c48b63b1", | ||
"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.84653f8a3c53", | ||
"version": "3.7.0-canary.8e16c48b63b1", | ||
"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
531545
7968