Skip to content

Feature/analytics#20

Closed
victorlucss wants to merge 10 commits into
developfrom
feature/analytics
Closed

Feature/analytics#20
victorlucss wants to merge 10 commits into
developfrom
feature/analytics

Conversation

@victorlucss

Copy link
Copy Markdown
Owner
Screen.Recording.2023-11-21.at.21.28.16.mov

@victorlucss victorlucss self-assigned this Nov 22, 2023
@vercel

vercel Bot commented Nov 22, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tonovermelho ❌ Failed (Inspect) Nov 24, 2023 7:44pm

const data = useMemo(() => {
const billsReduce = bills.reduce((prev, curr) => {
const dueDate = new Date(curr.dueDate);
const month = `${dueDate.getMonth() + 1}/${dueDate.getFullYear()}`;

@jefo3 jefo3 Mar 29, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would rename the variable name month to FormattedDueDate, as it doesn't actually represent the month, but rather the month/year of the due date

if (!prev[month]) {
prev[month] = {};

if (curr.type === BillTypes.EXPENSE) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From what I understand, this first check is to see if there are already values ​​for that specific month/year, if not yet, I put the curr values ​​as default

If my understanding is right

This part is not necessary if you initialize the expense and income values ​​to 0

Because in the next if you check if curr.type === billTypes.EXPENSE and do a prev[month].expense += curr.value;

If not, do: prev[month].income += curr.value;

Thus, repeating the code

So if the values ​​are initialized with zero, the += operation will work correctly and for cases where the information in the month/year did not yet exist, it becomes the curr value, exactly what the first if does

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

 if (!prev[month]) {
        prev[month] = {
          expense: 0,
          income: 0,
          month,
          rest: 0
        };
      }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But thinking here,
the code checks if there is no value in that table/year, if not, it initializes

there depending on whether the value of curr.type === BillTypes.EXPENSE
it initializes the expense with the value of curr.value
Then, as the value has already been initialized, it checks whether there is a value for the month/year ( if (prev?.[month]) )

as the prev for this month/year was initialized previously, it does: prev[month].expense += curr.value;

so it's as if it did a curr.values ​​+ curr.values for cases where the prev didn't yet have a value for that month

@victorlucss victorlucss closed this Mar 1, 2026
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