add solutions to Objects and Classes chapter#164
add solutions to Objects and Classes chapter#164cRAN-cg wants to merge 5 commits intosoftware-tools-books:masterfrom
Conversation
|
Hi @MayaGans could you please review |
gvwilson
left a comment
There was a problem hiding this comment.
Thanks for submitting this - feedback inline.
docs/answers.md
Outdated
|
|
||
| ```{js} | ||
| class Delay { | ||
| constructor(initialValue){ |
There was a problem hiding this comment.
Please use a space between the method name and the opening parenthesis, and between the closing parenthesis and curly brace:
constructor (initialValue) {
There was a problem hiding this comment.
Thanks for the review and have acknowledged the required changes to be made 👍
docs/answers.md
Outdated
| this.nextValue = initialValue | ||
| } | ||
|
|
||
| call(nextValue) { |
There was a problem hiding this comment.
Spacing as above please.
| } | ||
|
|
||
| call(inputValue){ | ||
| return this.filterValues.some((value) => value === inputValue) ? null : inputValue |
There was a problem hiding this comment.
It is probably more efficient to use indexOf:
return this.filterValues.indexOf(value) === -1 ? inputValue : null
There was a problem hiding this comment.
Hi @gvwilson,
I performed some tests out of curiosity to learn more about your suggestion.
I did run a performance test. The results showed me that both are comparatively same.
Please advise.
docs/answers.md
Outdated
|
|
||
| ```{js} | ||
| class Filter { | ||
| constructor(...values){ |
docs/answers.md
Outdated
| this.filterValues = values | ||
| } | ||
|
|
||
| call(inputValue){ |
docs/answers.md
Outdated
|
|
||
| ```{js} | ||
| class Pipeline { | ||
| constructor(...pipes){ |
docs/answers.md
Outdated
| this.pipes = pipes | ||
| } | ||
|
|
||
| call(inputValue){ |
docs/answers.md
Outdated
| } | ||
|
|
||
| call(inputValue){ | ||
| let returnValue |
There was a problem hiding this comment.
There is no need to introduce another variable: you can update inputValue repeatedly with inputValue = pipe.call(inputValue). (Although if you're going to do this, it should probably just be called value.)
docs/answers.md
Outdated
| call(inputValue){ | ||
| let returnValue | ||
| for (let pipe of this.pipes){ | ||
| returnValue = (() => pipe.call(inputValue))() |
There was a problem hiding this comment.
Why introduce the anonymous function call? Why not simply value = pipe.call(value)? (Assuming you unify the two variable inputValue and returnValue as described above.)
docs/answers.md
Outdated
| returnValue = (() => pipe.call(inputValue))() | ||
| if (!returnValue) break | ||
| inputValue = returnValue | ||
| } |
There was a problem hiding this comment.
Have we introduced break before this point in the text? If not, can you find a solution that does not use it?
Hi @gvwilson @MayaGans ! Could you please review
Also could you please advise the format for answers to questions under
Active Expressions