-
Notifications
You must be signed in to change notification settings - Fork 32
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
add solutions to Objects and Classes chapter #164
base: master
Are you sure you want to change the base?
Changes from 3 commits
f9cdcd9
5fc7520
30f819f
8807939
70c0585
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 |
---|---|---|
|
@@ -38,6 +38,58 @@ const annotateData = (array) => array.reduce(reducer, []) | |
const newData = annotateData(data) | ||
``` | ||
|
||
## Objects and Classes | ||
|
||
### Delays | ||
|
||
```{js} | ||
class Delay { | ||
constructor(initialValue){ | ||
this.nextValue = initialValue | ||
} | ||
|
||
call(nextValue) { | ||
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. Spacing as above please. |
||
let previousValue = this.nextValue | ||
this.nextValue = nextValue | ||
return previousValue | ||
} | ||
} | ||
``` | ||
|
||
### Filtering | ||
|
||
```{js} | ||
class Filter { | ||
constructor(...values){ | ||
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. spacing as above |
||
this.filterValues = values | ||
} | ||
|
||
call(inputValue){ | ||
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. spacing as above |
||
return this.filterValues.some((value) => value === inputValue) ? null : inputValue | ||
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. It is probably more efficient to use
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. Hi @gvwilson, |
||
} | ||
} | ||
``` | ||
|
||
### Pipelines | ||
|
||
```{js} | ||
class Pipeline { | ||
constructor(...pipes){ | ||
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. spacing as above |
||
this.pipes = pipes | ||
} | ||
|
||
call(inputValue){ | ||
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. spacing as above |
||
let returnValue | ||
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. There is no need to introduce another variable: you can update |
||
for (let pipe of this.pipes){ | ||
returnValue = (() => pipe.call(inputValue))() | ||
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. Why introduce the anonymous function call? Why not simply |
||
if (!returnValue) break | ||
inputValue = returnValue | ||
} | ||
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. Have we introduced |
||
return returnValue | ||
} | ||
} | ||
``` | ||
|
||
## Data-Forge | ||
|
||
### Revisting Data Manipulation | ||
|
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.
Please use a space between the method name and the opening parenthesis, and between the closing parenthesis and curly brace:
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.
Thanks for the review and have acknowledged the required changes to be made 👍