Skip to content

Commit

Permalink
feat(helpers): add blank lines to satisfy lint
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmayer committed Jan 1, 2023
1 parent ce272b3 commit 3164b38
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,13 @@ export class HelpersModule {
'weightedArrayElement expects an array with at least one element'
);
}

if (!array.every((elt) => elt.weight > 0)) {
throw new FakerError(
'weightedArrayElement expects an array of { weight, value } objects where weight is a positive number'
);
}

const total = array.reduce((acc, { weight }) => acc + weight, 0);
const random = this.faker.number.float({
min: 0,
Expand All @@ -501,6 +503,7 @@ export class HelpersModule {
return value;
}
}

// In case of rounding errors, return the last element
return array[array.length - 1].value;
}
Expand Down

0 comments on commit 3164b38

Please sign in to comment.