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|Zeliha-Pala | JS1 Module | [TECH ED] Complete week 3 exercises | Week 3 #172

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

Conversation

zelihapala
Copy link

@zelihapala zelihapala commented Nov 29, 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

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

if (angle === 360) return "Full angle";
if (angle < 360) return "Reflex angle";
return "Unknown angle";
}

Choose a reason for hiding this comment

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

I really like how you have wriiten your if statements in one line. It is easy to follow and easy to read.
I like that you also have a statement for unknown angle. That is really good. 👍 💯

Copy link
Author

Choose a reason for hiding this comment

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

Thank you.


function getCardValue(card) {
const cardRank = card.slice(0, -1);

Choose a reason for hiding this comment

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

I am a bit confused why you are using slice here. Could you explain please. Maybe I am missing your point of what you are trying to do.

Copy link
Author

Choose a reason for hiding this comment

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

i used it to extract the rank of the card from the card string
For instance, if card is "5♠", card.slice(0, -1) will return "5" because it's taking all characters from index 0 to the last character (-1 index is the last character in the string) excluding the last character ("♠" in this case).

} else {
throw new Error("Invalid card rank");
}
}

Choose a reason for hiding this comment

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

I learnt something new here. I did not know what !isNan and parseInt and throw new Error mean. But I looked up on MDN website and found the answer.
That is a pretty good code. Well done!

console.assert(
isProperFraction(3, 3) === false,
"Equal Numerator and Denominator failed"
);

Choose a reason for hiding this comment

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

This code is written nicely and clean. It is easy to follow and understand. Well done! 💯

console.assert(
isValidTriangle(0, 3, 3) === false,
"Zero side length is invalid"
);

Choose a reason for hiding this comment

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

Nice, clean, easy to follow code. 👍

Copy link

@HadikaMalik HadikaMalik left a comment

Choose a reason for hiding this comment

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

Your written code is ver nice and clean and easy to follow. Some parts of the code I found a bit too confusing but that was because I had never come across those terms and I actually learnt something new.
Well done! 👍 💯

Copy link
Contributor

@pseudopilot pseudopilot left a comment

Choose a reason for hiding this comment

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

Hi @zelihapala , this is a very good work!
I have only few comments for you. Mostly they are suggestions/recommendations about possible refactoring/improvements.
Only isProperFraction implementation seems to be a little buggy. I explained one corner case below.
Good luck!

Comment on lines 2 to +5
if (Number(time.slice(0, 2)) > 12) {
return `${Number(time.slice(0, 2)) - 12}:00 pm`;
return `${(Number(time.slice(0, 2)) - 12)
.toString()
.padStart(2, "0")}:${time.slice(time.indexOf(":") + 1)} pm`; // I got this part
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to refactor it a bit? You have same piece of code 2 times which may be stored in a variable instead: Number(time.slice(0, 2)).

Comment on lines +38 to +49
if (denominator === 0) {
return "Error: Denom cannot be 0";
} else if (numerator < denominator) {
return true;
} else if (numerator >= denominator) {
return false;
} else if (numerator < 0 && Math.abs(numerator) < denominator) {
return true;
// condition checks if the fraction has a negative numerator. The Math.abs() function finds the absolute value, which is the positive size or amount of a number, no matter if it's negative or positive. So, for a negative number, its absolute value gives the positive size of that number.
} else if (numerator === denominator) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There are few points here:

  1. you have few checks which return true and few which return false. Can you combine them to have only one check which returns true otherwise we just return false.

  2. in your code you have:

} else if (numerator < denominator) {
...
} else if (numerator < 0 && Math.abs(numerator) < denominator) {

I'm almost sure that if you have have negative numerator (like -10) and positive denominator (like 2) then your first check returns true and you won't even reach the second check.
But I think you can avoid this problem if you re-organise the function as I suggested in 1)

Comment on lines +43 to +49
if (a <= 0 || b <= 0 || c <= 0) {
return false;
}

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

Choose a reason for hiding this comment

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

You have 2 checks and both return false. Is it possible to merge them in one check?

Comment on lines +58 to +67
if (lowercaseAlphabet.includes(char)) {
// if lowercase letter
const rotatedIndex = (lowercaseAlphabet.indexOf(char) + shift) % 26; // read for me comment
return lowercaseAlphabet[rotatedIndex];
} else if (uppercaseAlphabet.includes(char)) {
const rotatedIndex = (uppercaseAlphabet.indexOf(char) + shift) % 26; // same for upperAlphabet
return uppercaseAlphabet[rotatedIndex];
} else {
return char; // (non-letter remains unchanged)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good and definitely should work. Though it may be optimised in a few ways:

  1. For now each time we call the function rotateCharacter we check/iterate the same string of letters 2 times:
  • 1st time when we call includes
  • 2nd time when we call indexOf
    Can we avoid using includes at all in this task and just use only indexOf and only once?
    What this method returns us when there is no value we search in string?
  1. In the worst case (e.g. the argument is a number) we will check 2 strings of letters before returning original value back. But I think we can use one string of letters (e.g. lowercaseAlphabet) instead of two if we utilise the string methods toLowerCase() and toUpperCase()

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