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

NW6 | Rabia Avci | JS1 Module | [TECH ED] Complete week 4 exercises | Week 4 #177

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

RbAvci
Copy link

@RbAvci RbAvci commented Dec 1, 2023

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Rewrite section (as written in Read me) is done, and get used to writing tests.
Implement section completed (except password-validator).

Questions

Copy link

@Ara225 Ara225 left a comment

Choose a reason for hiding this comment

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

Good work, I'm moaning about your loops quite a bit. I think you should have a look at loops and some of the array functions again and make sure that you understand

}
if (count === 16) {
return false;
}
Copy link

Choose a reason for hiding this comment

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

Good work, like the comments as well

Just a small comment (not a telling off or something to be fixed) Loops can be quite bad performance wise and this code isn't the easiest to read, so in the real world I'd be looking hard for shortcuts when I came to refactor. One that springs to mind is

let badCardNum = cardNum[0] * 16;
if (cardNum === badCardNum) {
     return false;

}
if (total < 16) {
return false;
}
Copy link

Choose a reason for hiding this comment

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

Works perfectly and appreciate the comments here, afraid I have two of my own.

  • Don't use the same varible for index - it causes bugs something like this is better while (let index ....) This way each loop manages it's own index.
  • There is a simpler way of doing this - genrally speaking when there's something like this that is often done, there will be (you'll develop a nose for this eventually)

I would use .split() to make the string into an array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split and then call .reduce() on the array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

const currentOutput2 = isValidCardNumber(num2);

//THEN
expect(currentOutput1).toBe(targetOutput);
Copy link

Choose a reason for hiding this comment

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

Nice tests - overall good work needs a little refactoring I think

let count = 0;
let index = 0;

while (index < str.length){
Copy link

Choose a reason for hiding this comment

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

Good work. I do want to see you stopping defining index outside of the loop though. I would also have a look at diffrent types of loops - a for ... in loop would be a better and easier one to use here. https://buzzcoder.gitbooks.io/codecraft-javascript/content/string/loop-through-a-string.html


test("works for any other number", function () {
expect(getOrdinalNumber(7)).toBe("7th");
expect(getOrdinalNumber(99)).toBe("99th");
Copy link

Choose a reason for hiding this comment

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

Very nice work, no complaints

// d) What is the condition index < str.length used for?
// to define when to stop checking characters
Copy link

Choose a reason for hiding this comment

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

All correct

return `${"Straight angle"}`;
}
else if (angle>180 && angle<360){
return `${"Reflex angle"}`;
Copy link

Choose a reason for hiding this comment

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

All correct. I would avoid using backticks here; they aren't needed, you can just return a string

return 10;
}
throw Error("Invalid card rank.");
}
Copy link

Choose a reason for hiding this comment

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

Simple effective solution with excellent testing 👍

if (numerator < denominator) {
return true;
} else if (numerator > denominator || numerator === denominator) {
return false;
Copy link

Choose a reason for hiding this comment

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

👍

if (a <= 0 || b <= 0 || c <= 0) {
return false;
}
if (a + b <= c || a + c <= b || b + c <= a) {
Copy link

Choose a reason for hiding this comment

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

Looking good :)

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