-
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
Develop #2388
base: master
Are you sure you want to change the base?
Develop #2388
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
|
||
module.exports = makeRobotAccountant; |
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. 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.