Skip to content

Post with publishDate and date appears twice.#3

Open
jkuebart wants to merge 1 commit intohellatan:masterfrom
jkuebart:patch-2
Open

Post with publishDate and date appears twice.#3
jkuebart wants to merge 1 commit intohellatan:masterfrom
jkuebart:patch-2

Conversation

@jkuebart
Copy link

@jkuebart jkuebart commented Oct 9, 2019

If a post has publishDate and date, it is archived for both dates.

This happens because in the first iteration (publishDate), the post is added to the archive and valueFound is set to true. In the second iteration (modifiedDate), valueFound is set to false in the else branch. That's why in the third iteration (date), the post is added to the archive again for that year.

Generally, I would prefer a for loop or Array.prototype.reduce() when early exit is needed, Array.protoype.forEach() isn't really suitable for this.

To test this, a post should be added to the fixtures which has publishDate and date in different years, but no modifiedDate.

If a post has `publishDate` and `date`, it is archived for both dates.

This happens because in the first iteration (`publishDate`), the post is added to the archive and `valueFound` is set to `true`. In the second iteration (`modifiedDate`), `valueFound` is set to `false` in the `else` branch. That's why in the third iteration (`date`), the post is added to the archive again for that year.

Generally, I would prefer a `for` loop or `Array.prototype.reduce()` when early exit is needed, `Array.protoype.forEach()` isn't really suitable for this.

To test this, a post should be added to the fixtures which has `publishDate` and `date` in different years, but no `modifiedDate`.
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.

1 participant