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

All tests are completed #2378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/makeRobotAccountant.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@
*/

function makeRobotAccountant() {
// write code here
let count = 0;

function getSum(number) {
return function(value) {
count++;

const result = value + number;

if (count % 2 === 0 && count > 3) {

Choose a reason for hiding this comment

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

You should use one variable for counting function calls. Here, you are using count correctly to keep track of the calls to the returned function.

Choose a reason for hiding this comment

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

Consider combining the conditions in the if statement to avoid nesting ternary operators or multiple if-else statements. Since you're only checking one condition, it's not necessary to use an else statement; you can return result directly after the if block.

return 'Bzzz... Error!';
} else {
return result;
}
};
}
Comment on lines +11 to +23

Choose a reason for hiding this comment

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

The inner function returned by getSum should not be named. You can simply return an anonymous function.


return getSum;
}

module.exports = makeRobotAccountant;
Loading