-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Solution #2386
base: master
Are you sure you want to change the base?
Solution #2386
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on your Pull Request! There are no critical issues, and it looks like you're following good coding practices. Just a friendly reminder to avoid nesting ternary operators in the future, but that's not a blocker for approval. Keep up the good work! 👍💻
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
src/makeRobotAccountant.js
Outdated
return (operator) => { | ||
if (callCounter > 3 && callCounter % 2 === 0) { | ||
return 'Bzzz... Error!'; | ||
} | ||
|
||
return num + operator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CODE STYLE] - Don't nest ternary operators. You're using an if statement inside a returned function which is okay, but make sure to avoid nesting ternary operators as per the code style guide.
src/makeRobotAccountant.js
Outdated
const getSum = (num) => { | ||
callCounter++; | ||
|
||
return (operator) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CODE STYLE] - You don't need to name functions if you return them right away. In this case, the function returned from getSum
is anonymous as it should be, which aligns with the code style guide.
@@ -7,6 +7,21 @@ | |||
|
|||
function makeRobotAccountant() { | |||
// write code here | |||
let callCounter = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CODE STYLE] - You should use one variable for counting function calls, which you have correctly implemented here with callCounter
.
src/makeRobotAccountant.js
Outdated
if (callCounter > 3 && callCounter % 2 === 0) { | ||
return 'Bzzz... Error!'; | ||
} | ||
|
||
return num + operator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CODE STYLE] - DRY. When you do similar logic, try to combine conditions. In this case, you have separated the logic for error handling and returning the sum, which is appropriate as they are distinct behaviors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey. This can be simplified by directly returning functions.
src/makeRobotAccountant.js
Outdated
const getSum = (num) => { | ||
callCounter++; | ||
|
||
return (operator) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a second number not operator that you provide through params.
src/makeRobotAccountant.js
Outdated
let callCounter = 0; | ||
|
||
const getSum = (num) => { | ||
callCounter++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callCounter should be incremented inside the second, deeper function.
src/makeRobotAccountant.js
Outdated
@@ -7,6 +7,21 @@ | |||
|
|||
function makeRobotAccountant() { | |||
// write code here | |||
let callCounter = 0; | |||
|
|||
const getSum = (num) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can return getSum function right away instead of declaring it first and then returning it ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
No description provided.