-
Notifications
You must be signed in to change notification settings - Fork 3k
Solution #3070
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
base: master
Are you sure you want to change the base?
Solution #3070
Changes from all 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 |
|---|---|---|
|
|
@@ -4,7 +4,43 @@ | |
| * @return {object} | ||
| */ | ||
| function makeCalculator() { | ||
| // write code here | ||
| } | ||
| let result = 0; | ||
|
|
||
| const add = (a, b) => a + b; | ||
| const subtract = (a, b) => a - b; | ||
| const multiply = (a, b) => a * b; | ||
| const divide = (a, b) => a / b; | ||
|
|
||
| const operate = function (callback, num) { | ||
|
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. This |
||
| if (callback === add) { | ||
|
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. The chain of |
||
| result += num; | ||
| } else if (callback === subtract) { | ||
| result -= num; | ||
| } else if (callback === multiply) { | ||
| result *= num; | ||
| } else if (callback === divide) { | ||
| result /= num; | ||
| } | ||
|
|
||
| return this; | ||
| }; | ||
|
Comment on lines
+14
to
+26
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. This violates checklist item #3: "[CODE KNOWLEDGE] - if you creating a method in the object, you don't need to use function keyword, use shortcut instead." |
||
|
|
||
| const reset = function () { | ||
|
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. This violates checklist item #3: 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.
|
||
| result = 0; | ||
|
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. This also violates checklist item #2: 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.
|
||
|
|
||
| return this; | ||
| }; | ||
|
Comment on lines
+28
to
+32
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. This violates checklist item #3 again: |
||
|
|
||
| return { | ||
| get result() { | ||
| return result; | ||
| }, | ||
| add, | ||
| subtract, | ||
| multiply, | ||
| divide, | ||
| operate, | ||
|
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. In the returned object, |
||
| reset, | ||
| }; | ||
| } | ||
| module.exports = makeCalculator; | ||
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.
This violates checklist item #3:
if you are creating a method in the object, you don't need to use function keyword, use shortcut instead.Definingoperateas a separateconstfunction rather than a method on the returned object uses the bad pattern from the checklist.