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

Develop #2388

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Develop #2388

Changes from 2 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
21 changes: 17 additions & 4 deletions src/makeRobotAccountant.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
'use strict';
"use strict";

/**
*
* @return {function}
*/

function makeRobotAccountant() {
// write code here
// Licznik wywołań, początkowo 0
let callCount = 0;

// Funkcja zwracana przez makeRobotAccountant
return function (a) {
return function (b) {
callCount++;

// Sprawdzamy, czy to czwarte lub kolejne wywołanie
if (callCount > 3 && callCount % 2 === 0) {
return "Bzzz... Error!";
} else {
return a + b;
}

Choose a reason for hiding this comment

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

[CODE STYLE] - DRY. You can combine conditions to simplify the logic. For instance, you can check if callCount is less than or equal to 3 to return the sum directly, reducing the need for an else block.

};

Choose a reason for hiding this comment

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

[CODE STYLE] - Try not to nest ternary operators. Instead, you can use a single conditional statement or separate the logic into multiple statements to improve readability.

};
}

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. Consider using anonymous functions instead to make the code cleaner. For example, return function (b) { ... };


module.exports = makeRobotAccountant;
Loading