Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: provide initial values to reduce functions in generated js #6178

Merged
merged 1 commit into from
May 31, 2022

Conversation

gregdyke
Copy link
Contributor

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

#6169

Proposed Changes

Generated code using reduce (average and sum) has initial value set to 0

Behavior Before Change

Runtime error when calling average or sum on an empty list in javascript

Behavior After Change

No runtime error

Reason for Changes

Reduce without an initial value takes the 1st element in the array as the initial value in javascript -> needs an initial value for empty lists.

Note

  • mean of an empty list still produces NaN (expected)
  • std dev returns null for empty lists already so does not need an initial value passed to reduce

Test Coverage

Adjusted existing tests to new generated code

Documentation

Additional Information

@gregdyke gregdyke requested a review from a team as a code owner May 29, 2022 23:56
@gregdyke gregdyke requested a review from BeksOmega May 29, 2022 23:56
Copy link
Collaborator

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the fix, and for updating tests :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants