Solve 2025-08
This commit is contained in:
@@ -135,6 +135,13 @@ export function uniqueCombinations<E>(arr: ReadonlyArray<E>): { a: E; b: E }[] {
|
||||
arr.flatMap((b, bI) => (a !== b && aI > bI ? [{ a, b }] : []))
|
||||
);
|
||||
}
|
||||
export function uniqueIndexCombinations<E>(
|
||||
arr: ReadonlyArray<E>
|
||||
): { aI: number; bI: number }[] {
|
||||
return arr.flatMap((a, aI) =>
|
||||
arr.flatMap((b, bI) => (a !== b && aI > bI ? [{ aI, bI }] : []))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a filter lambda to be used in array.filter() to only allow the
|
||||
|
||||
+11
-1
@@ -1,4 +1,4 @@
|
||||
import { sumBy } from './array.ts';
|
||||
import { sumArray, sumBy } from './array.ts';
|
||||
|
||||
export const Sides = {
|
||||
TOP: 0,
|
||||
@@ -167,3 +167,13 @@ export function calculateVariance<C extends Coordinate | CoordinateSide>(
|
||||
coords.length
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: add docs and tests
|
||||
|
||||
export function euclideanDistanceSqrtless(a: number[], b: number[]): number {
|
||||
return sumArray(a.map((d, i) => Math.pow(d - b[i], 2)));
|
||||
}
|
||||
|
||||
export function euclideanDistance(a: number[], b: number[]): number {
|
||||
return Math.sqrt(euclideanDistanceSqrtless(a, b));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user