-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added code and tests for event stream puzzler #40
base: Daniel-EventStream
Are you sure you want to change the base?
Conversation
src/index.ts
Outdated
export interface EventInput { |
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.
export interface EventInput { | |
export interface Event { |
src/index.ts
Outdated
export interface EventInput { | ||
timestamp: Readonly<number>, | ||
eventType: Readonly<string> |
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 type should limit values to only be one of the three defined options.
src/index.ts
Outdated
|
||
private _scoreTable: Record<Readonly<string>, Readonly<number>> = { | ||
["newMessage"]: 1, |
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.
brackets shouldn't be needed here
src/index.ts
Outdated
|
||
private _setSortedWinners() { | ||
const numOfRegions: number = 1 + (this._data.length - 5) |
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.
don't have to type this as number. easily inferred by TS
src/index.ts
Outdated
const numOfRegions: number = 1 + (this._data.length - 5) | ||
if (numOfRegions < 1) { | ||
throw "Not enough events to score. Please provide at least five" |
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.
if the number of events is less than or equal to five, the function should return all events.
src/index.test.ts
Outdated
expect(badEventStream).toThrow("Input of object was found. Please provide a valid array.") | ||
}) | ||
|
||
it("should fail with not enough obj provided", () => { |
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.
if number of events is less than or equal to five, return all items.
src/index.test.ts
Outdated
}) | ||
}) | ||
|
||
describe('getUnsortedScores()', () => { |
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 is not a requirement of the puzzle.
src/index.test.ts
Outdated
}) | ||
}) | ||
|
||
describe('getSortedScores()', () => { |
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.
not part of the requirments
src/index.ts
Outdated
regionId: regionNum, | ||
score: regionScore, | ||
inputLocations: [...regionNumbers] |
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.
i'm unclear about the purpose of inputLocations. If we know the starting index of the highest scoring region, then we can calculate the range of the region.
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! It was for getSortedScores() but I will remove that, then the input locations, per your previous comment
Try to refactor all of your for loops to use Higher Order functions like |
export interface Event { | ||
timestamp: Readonly<number>, | ||
eventType: Readonly<"newMessage" | "view" | "screenshot"> |
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.
using the readonly
decorator would also be fine.
...
readonly timestamp: number,
...
|
||
export function getWinningRegion(inputData: ReadonlyArray<Event>): ReadonlyArray<Event> { | ||
const scoreTable = { |
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.
for the sake of this excercise, i'd like you:
encapsulate the scoring of a single event into a single function. Should return a number
encapsulate the scoring of an array into a single function. Should return a number
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! Hopefully my changes are what you were looking for!
Ticket:
N/a
What this PR does
This PR request adds the following
Media
![image](https://user-images.githubusercontent.com/7016167/173706221-5f8789a1-537c-4989-aacc-952385e5f7aa.png)
How to test
To test, clone the repository to your computer and navigate to the project with the terminal. Download all necessary packages with yarn install and when ready, run yarn run test to execute the application. You should see several tests and the results of these tests.
To use your own seed data, please enter the following at the bottom of index.ts, replacing [] with your event stream input array.
Once you've added in your code, in the terminal run yarn run dev to see the output