Skip to content
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

EventScoreAPI #11

Open
wants to merge 3 commits into
base: ms-training-2
Choose a base branch
from
Open

EventScoreAPI #11

wants to merge 3 commits into from

Conversation

michmitz
Copy link

What this does:

  • Creates a class, EventScoreAPI
  • EventScoreAPI has two properties: score and eventArr
  • Method - calcHighestScoreArrSequence - returns a contigous sub array derived from eventArr property, no greater than five elements, with the highest score. Score is determined by event type on event element:
    • screenshot = 3
    • views = 2
    • new message = 1

Copy link
Contributor

@ianandrewson ianandrewson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely on the right track with your algorithm.


describe('EventScore API', () => {
it('Returns an entire array if it is five events or less', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth having tests for edge cases: arrays of length 0 and 5.

src/index.ts Outdated
} else tempCount += 1

if (i > 4) {
if (eventType[i - 1] === "screenshot") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to subtract from tempCount the most recent value added?

} else {
this.eventArr.map((event, i) => {
const { eventType } = event
if (eventType === "screenshot") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, can definitely refactor the conversion of eventType to a scoring value.


public calcHighestScoreArrSequence = (): ReadonlyArray<Event> => {
let tempCount: number = 0
let highestScoreArr: ReadonlyArray<Event> = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While insignificant in this case, as highestScoreArr is going to have max length of 5, it is possible to solve this without storing the returned highestScoreArr, and instead just directly return it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants