Skip to content

Conversation

devmooo3
Copy link
Collaborator

Quality Checklist

  • I took the time to compare my implementation with the design.
  • I ensured that the this pull request satisfies all the requirements in the associated task.
  • I performed a self-review.

Links

Important

Incase you have any valuable knowledge that you think that it is worth writing down, feel free to add it to our handbook. Wounder why we are doing this? check this guide.

@devmooo3 devmooo3 requested a review from mmoehabb July 24, 2025 13:34
@devmooo3 devmooo3 self-assigned this Jul 24, 2025
@neuodev
Copy link
Member

neuodev commented Jul 24, 2025

Warnings
⚠️ No clickup task found in this pull request

Generated by 🚫 dangerJS against c1fe6b0

@neuodev
Copy link
Member

neuodev commented Jul 24, 2025

🚀 WEB
🚀 UI
🚀 LANDING
🚀 DASHBOARD

@neuodev
Copy link
Member

neuodev commented Jul 24, 2025

🚀 WEB
🚀 UI
🚀 LANDING
🚀 DASHBOARD

@neuodev
Copy link
Member

neuodev commented Jul 24, 2025

🚀 WEB
🚀 UI
🚀 LANDING
🚀 DASHBOARD

Copy link
Collaborator

@mmoehabb mmoehabb left a comment

Choose a reason for hiding this comment

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

Please write unit tests for this method.

@devmooo3 devmooo3 force-pushed the devmo/valid-bank-number branch from c1fe6b0 to 059b72c Compare August 3, 2025 14:43
@devmooo3 devmooo3 requested a review from mmoehabb August 3, 2025 14:48
@neuodev
Copy link
Member

neuodev commented Aug 3, 2025

🚀 WEB
🚀 UI
🚀 LANDING
🚀 DASHBOARD

Comment on lines +107 to +109
.reduce((sum, digit) => sum + digit, 0) %
10 ===
0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks so ugly.

.reverse()
.map((char, index) => {
const digit = Number(char);
return index % 2 === 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer writing declarative code; use isEven or isOdd functions.

if (isNaN(Number(bankNumber))) {
return FieldError.InvalidBankAccountNumber;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

The length of bank numbers varies between 9 digits to 12. We may use that as well before commencing on the luhn algorithm.

Comment on lines +102 to +105
? digit * 2 > 9
? digit * 2 - 9
: digit * 2
: digit;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is unreadable at all. It's logic is correct 100%, but it's hard to read. Try using if statements instead.
Moreover, try to write the algorithm yourself first:

Algorithm isValidBankAccount:
   Input: bankNumber - string of the bank number
   Output: true or false
   
   sum <- 0
   for each digit in the bank number do the following
       d <- the digit
       if the digit is an even number
           sum <- sum + d
           continue
       ... 

Remember, you will never learn by allotting everything to the AI.

You way manna write the function in an empty JS file in order to be able to experiment and execute it easily with node.

import {
generateValidLuhnNumber,
generateInvalidLuhnNumber,
} from "./luhnGenerator";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Relative imports are not recommended.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This's not how we write unit tests. Use AI as a tool only. You are the coder; read other unit tests files and follow its pattern or so to speak our implicit convention of writing tests.

the unit tests should be added in the invoice.test.ts file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the note🫡

Copy link
Collaborator

Choose a reason for hiding this comment

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

First of all, only test files, like {entity}.test.ts, are stored in the tests directory. This shouldn't be store here. You may write these functions within the file that uses them. Second, I don't believe this is the best approach. I prefer using just multiple valid and invalid bank account numbers.

We may use the ones being used by check50:
https://github.com/cs50/problems/blob/2025/x/credit/__init__.py

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.

3 participants