NW6| Sabella -Fisseha| JS1 | Week4/Exercise #180
NW6| Sabella -Fisseha| JS1 | Week4/Exercise #180Sabella-8 wants to merge 6 commits intoCodeYourFuture:mainfrom
Conversation
|
|
||
| for (let i = 2; i < num; i++) { | ||
| if (num % i === 0) { | ||
| return `${num} is not prime`; |
There was a problem hiding this comment.
Great use of short-circuiting here @Sabella-8! If we know a number is definitely prime, we can stop the loop and return, without any more computation.
| const currentOutput = getOrdinalNumber(input); | ||
| const targetOutput = "1st"; | ||
|
|
||
| expect(currentOutput).toBe(targetOutput); |
There was a problem hiding this comment.
There's quite a few branches in your implementation. Don't be afraid to write lots of test cases that check different possibilities.
| // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. | ||
| function countOccurrences(input, char) { | ||
| const num = input.split(char).length - 1 | ||
| if(num => 1) |
There was a problem hiding this comment.
Check your syntax here @Sabella-8. Remember that => means something different to >=
| const num = input.split(char).length - 1 | ||
| if(num => 1) | ||
| return `${char} occurs ${num} times`; | ||
| else{`${char} occurs 0 times`; |
There was a problem hiding this comment.
Make sure that Prettier is installed and working in Visual Studio Code. This would help to keep formatting consistent, especially around if blocks
| for (let i = 0; i < num.length - 1; i += 2) { | ||
| add += num[i] + num[i + 1]; | ||
| } |
There was a problem hiding this comment.
I think this loop is slightly more complicated than it needs to be. If we go from i == 0 to i < num.length, we will already visit each number once. Then we only need to add the current element, instead of the current element and the one after that
| @@ -0,0 +1,36 @@ | |||
| // Number must be 16 digits, all of them must be numbers. | |||
| // - You must have at least two different digits represented (all of the digits cannot be the same). | |||
| // - The final digit must be even. | |||
There was a problem hiding this comment.
Is there anywhere that the final digit gets checked for odd-/even-ness?
areebsattar
left a comment
There was a problem hiding this comment.
It looks like you were branching from the branches themselves which resulted in a lot of file changes here! Is that the case? Apart from that I really like how you write the code as it's easy to read and understand
| const currentOutput = checkPassword(str); | ||
| const targetOutput = "password is valid"; | ||
| expect(currentOutput).toBe(targetOutput); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
I like the implementation of code here it;s easy to understand
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.