Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekkosiba committed Nov 10, 2023
1 parent 9b9a80d commit 0e7b9f2
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 18 deletions.
81 changes: 67 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^0.3.6",
"@mate-academy/scripts": "^1.2.8",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Sum with a closure

Accounting, numbers, many numbers. Boring. The solution is to automate! The first robot accountant came off the assembly line. I don't know how accountants' brains don't melt, but when our robot starts adding numbers, it starts to burn significantly and it counts every other time.
Reproduce the behavior of our robots. Create a function `makeRobotAccountant`, the result of which is a function that works on the pattern `getSum (4) (5) === 9`.
The first 3 calls to this feature work fine. Then all even calls return the string `Bzzz... Error!`, And odd calls the correct value.
Reproduce the behavior of our robots.

Create a function `makeRobotAccountant`,
the result of which is a function
that works on the pattern `getSum (4) (5) === 9`.
The first 3 calls to this feature work fine.
Then all even calls return the string `Bzzz... Error!`
, And odd calls the correct value.

Example:
```
Expand Down
14 changes: 13 additions & 1 deletion src/makeRobotAccountant.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
*/

function makeRobotAccountant() {
// write code here
let counter = 0;
return function (a) {
return function (b) {
counter++;

if (counter > 3 && counter % 2 === 0) {
return 'Bzzz... Error!';
}

return a + b;
}
}
}


module.exports = makeRobotAccountant;

0 comments on commit 0e7b9f2

Please sign in to comment.