-
Notifications
You must be signed in to change notification settings - Fork 2
* I'am finished the homework #2
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
base: develop-vachagan
Are you sure you want to change the base?
Conversation
| var isPrime = true; | ||
| for (j = 2; j < startPrimeNum; j++) { | ||
| if (startPrimeNum % j === 0) { | ||
| isPrime = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop will do 998 iterations, if startPrimeNum is 1000.
But after first iteration it's clear, that 1000 is not prime, so it will be better to break; the loop once the condition is satisfied.
| @@ -1,38 +1,36 @@ | |||
| var num = parseInt(prompt('Enter a natural number or "exit"')); | |||
| var num = prompt('Enter a natural number or "exit"'); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance it's not clear why this line is outside the loop. It's a bit confusing. If this line goes into top of while loop, the code will be clearer.
| primeArr[j] = primeArr[j + 1]; | ||
| primeArr[j + 1] = c; | ||
| for (var i = 0; i < primeArr.length - 1; i++) { | ||
| for (var j = 0; j < primeArr.length - 1; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see bubble sort implementation here, but both loops run from 0 to primeArr.length, so primeArr.length^2 operations will be performed. But if first loop starts at i, instead of 0, only (primeArr.length * (primeArr.length + 1)) / 2 operations will be performed, which is much better.
src/assignment0.js
Outdated
| for (var j = 2; j < k; j++) { | ||
| if (k % j === 0) { | ||
| return false; | ||
| var count = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These numbers are confusing at first glance. Why 1 ? Why [2], why 3 ? I see your intention, but still, this is confusing. Please set count to 0, primeArray to empty array ([]) and startPrimeNum to 2. BTW add a comment to this line like:
var startPrimeNum = 2; // The first prime number
so it will be clear what this number is about.
No description provided.