Skip to content

Commit

Permalink
Fix float count issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman committed Nov 22, 2024
1 parent 16ce08f commit 3982324
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drizzle-seed/src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const fastCartesianProduct = (sets: (number | string | boolean | object)[
* @returns Example: with weights = [0.2, 0.8] and accuracy = 10 returning array of indices gonna equal this: [0, 0, 1, 1, 1, 1, 1, 1, 1, 1]
*/
export const getWeightedIndices = (weights: number[], accuracy = 100) => {
const weightsSum = weights.reduce((acc, currVal) => acc + currVal, 0);
const weightsSum = Math.round(weights.reduce((acc, currVal) => acc + currVal, 0));
if (weightsSum !== 1) {
throw new Error(`sum of all weights don't equal to 1; ${weightsSum} !== 1`);
}
Expand Down

0 comments on commit 3982324

Please sign in to comment.