Skip to content

Remove side effect from array.some callback#184919

Merged
Tyriar merged 1 commit into
microsoft:mainfrom
CodinGame:remove-side-effect-in-expected-pure-function
Jun 13, 2023
Merged

Remove side effect from array.some callback#184919
Tyriar merged 1 commit into
microsoft:mainfrom
CodinGame:remove-side-effect-in-expected-pure-function

Conversation

@CGNonofr

Copy link
Copy Markdown
Contributor

some method callback is supposed to be side-effect free. Also, findIndex is now well supported

@mjbvz mjbvz assigned Tyriar and unassigned mjbvz Jun 12, 2023

@Tyriar Tyriar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks good, but I'm missing where the side effect is?

@Tyriar Tyriar added this to the June 2023 milestone Jun 12, 2023
@CGNonofr

Copy link
Copy Markdown
Contributor Author

The index variable is declared outside of the callback and modified inside the callback

@Tyriar Tyriar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I thought you meant _getTerminalObjectIndexById has a side effect. I wouldn't call .some setting some value outside it's callback a problem, it's basically the same thing as doing it with a for loop. Regardless, the code looks better with your changes so thanks 🙂

@CGNonofr

Copy link
Copy Markdown
Contributor Author

Oh I thought you meant _getTerminalObjectIndexById has a side effect. I wouldn't call .some setting some value outside it's callback a problem, it's basically the same thing as doing it with a for loop. Regardless, the code looks better with your changes so thanks slightly_smiling_face

It's a problem it you want to tree-shake the code and expect calls to some to be side-effect free

@Tyriar Tyriar merged commit a656c21 into microsoft:main Jun 13, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants