-
Notifications
You must be signed in to change notification settings - Fork 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
adding get-simple-numbers.js #1
base: master
Are you sure you want to change the base?
Conversation
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.
Please follow same repository structure like in other HowProgrammingWorks repositories:
- We place js examples in
JavaScript
, not inlib
, because this is not library and we may implement this in other languages - Use eslint with
.eslintrc.yml
rules from other HPW repo, for example .eslintrc.yml but don't commit it in pull request with your code - Add
'use strict';
to your code - See other comment in code
- Use
eslint .
before commit
lib/get-simple-numbers.js
Outdated
@@ -0,0 +1,23 @@ | |||
sort = (array, divider) => { |
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.
Declare with const
lib/get-simple-numbers.js
Outdated
} | ||
|
||
console.log("array after erasing: " + array); | ||
if(erased == 0) return array.sort((a,b) => a-b); |
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.
===
lib/get-simple-numbers.js
Outdated
} | ||
|
||
if(process.argv.length > 2) console.log("\nresult: " + getArrayOfSimpleNumbers(process.argv[2])); | ||
else console.log("Program created for getting simple number using sieve of Eratosthenes.\nusage:\n node ./get-simple-numbers.js [renge of numbers]"); |
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.
Max line length: 80 chars
Add empty line at the end of file
lib/get-simple-numbers.js
Outdated
@@ -0,0 +1,23 @@ | |||
sort = (array, divider) => { | |||
console.log("divider: " + divider); |
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.
Use single quotes
lib/get-simple-numbers.js
Outdated
sort = (array, divider) => { | ||
console.log("divider: " + divider); | ||
let erased = 0; | ||
for(value of array) if(value % divider === 0 && value != divider) { |
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.
Add spaces, code blocks and use !==
instead of !=
I've done
сб, 22 вер. 2018 о 10:17 Timur Shemsedinov <[email protected]> пише:
… ***@***.**** requested changes on this pull request.
Please follow same repository structure like in other HowProgrammingWorks
repositories:
- We place js examples in JavaScript, not in lib, because this is not
library and we may implement this in other languages
- Use eslint with .eslintrc.yml rules from other HPW repo, for example
.eslintrc.yml
<https://github.com/HowProgrammingWorks/Wrapper/blob/master/.eslintrc.yml>
but don't commit it in pull request with your code
- Add 'use strict'; to your code
- See other comment in code
- Use eslint . before commit
------------------------------
In lib/get-simple-numbers.js
<#1 (comment)>
:
> @@ -0,0 +1,23 @@
+sort = (array, divider) => {
Declare with const
------------------------------
In lib/get-simple-numbers.js
<#1 (comment)>
:
> @@ -0,0 +1,23 @@
+sort = (array, divider) => {
+ console.log("divider: " + divider);
+ let erased = 0;
+ for(value of array) if(value % divider === 0 && value != divider) {
+ array.splice(array.indexOf(value), 1);
+ array.splice(array.indexOf(divider), 1);
+ array.push(divider);
+ erased++;
+ }
+
+ console.log("array after erasing: " + array);
+ if(erased == 0) return array.sort((a,b) => a-b);
===
------------------------------
In lib/get-simple-numbers.js
<#1 (comment)>
:
> + erased++;
+ }
+
+ console.log("array after erasing: " + array);
+ if(erased == 0) return array.sort((a,b) => a-b);
+ return sort(array, array[0]);
+}
+
+getArrayOfSimpleNumbers = range => {
+ let array = [];
+ for(let i = 2; i < range; i++) array.push(i);
+ return sort(array, array[0]);
+}
+
+if(process.argv.length > 2) console.log("\nresult: " + getArrayOfSimpleNumbers(process.argv[2]));
+else console.log("Program created for getting simple number using sieve of Eratosthenes.\nusage:\n node ./get-simple-numbers.js [renge of numbers]");
Max line length: 80 chars
Add empty line at the end of file
------------------------------
In lib/get-simple-numbers.js
<#1 (comment)>
:
> @@ -0,0 +1,23 @@
+sort = (array, divider) => {
+ console.log("divider: " + divider);
Use single quotes
------------------------------
In lib/get-simple-numbers.js
<#1 (comment)>
:
> @@ -0,0 +1,23 @@
+sort = (array, divider) => {
+ console.log("divider: " + divider);
+ let erased = 0;
+ for(value of array) if(value % divider === 0 && value != divider) {
Add spaces, code blocks and use !== instead of !=
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AWHrv2DKFCOoukAMBk0oZWzA27OesVdCks5udeQXgaJpZM4W0zoO>
.
|
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.
- You have placed example to repository root folder, but we usually place into language-specific folders,
JavaScript
orHaskell
get-simple-numbers.js
Outdated
const sort = (array, divider) => { | ||
console.log('divider: ' + divider); | ||
let erased = 0; | ||
for (const value of array) if (value % divider === 0 && value !== divider) { |
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'd prefer:
for (...) {
if (...) {
}
}
get-simple-numbers.js
Outdated
return sort(array, array[0]); | ||
}; | ||
|
||
if (process.argv.length > 2) |
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.
It would be better having operator block {}
for then
branch if we have block for else
branch
get-simple-numbers.js
Outdated
if (process.argv.length > 2) | ||
console.log('\nresult: ' + getArrayOfSimpleNumbers(process.argv[2])); | ||
else { | ||
console.log('Program allows getting simple number'); |
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.
Program generates simple numbers using Sieve of Eratosthenes
Usage: node ./generate-simple-numbers [max]
Example: node ./generate-simple-numbers 100
done
нд, 23 вер. 2018 о 04:23 Timur Shemsedinov <[email protected]> пише:
… ***@***.**** requested changes on this pull request.
- You have placed example to repository root folder, but we usually
place into language-specific folders, JavaScript or Haskell
------------------------------
In get-simple-numbers.js
<#1 (comment)>
:
> @@ -0,0 +1,30 @@
+'use strict';
+
+const sort = (array, divider) => {
+ console.log('divider: ' + divider);
+ let erased = 0;
+ for (const value of array) if (value % divider === 0 && value !== divider) {
I'd prefer:
for (...) {
if (...) {
}
}
------------------------------
In get-simple-numbers.js
<#1 (comment)>
:
> + array.push(divider);
+ erased++;
+ }
+
+ console.log('array after erasing: ' + array);
+ if (erased === 0) return array.sort((a, b) => a - b);
+ return sort(array, array[0]);
+};
+
+const getArrayOfSimpleNumbers = range => {
+ const array = [];
+ for (let i = 2; i < range; i++) array.push(i);
+ return sort(array, array[0]);
+};
+
+if (process.argv.length > 2)
It would be better having operator block {} for then branch if we have
block for else branch
------------------------------
In get-simple-numbers.js
<#1 (comment)>
:
> +
+ console.log('array after erasing: ' + array);
+ if (erased === 0) return array.sort((a, b) => a - b);
+ return sort(array, array[0]);
+};
+
+const getArrayOfSimpleNumbers = range => {
+ const array = [];
+ for (let i = 2; i < range; i++) array.push(i);
+ return sort(array, array[0]);
+};
+
+if (process.argv.length > 2)
+ console.log('\nresult: ' + getArrayOfSimpleNumbers(process.argv[2]));
+else {
+ console.log('Program allows getting simple number');
Program generates simple numbers using Sieve of Eratosthenes
Usage: node ./generate-simple-numbers [max]
Example: node ./generate-simple-numbers 100
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AWHrvxh8U-1sNzfJbQFY0oWdttU8FD-_ks5uduJ0gaJpZM4W0zoO>
.
|
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.
Now we can start with code refactoring:
- Names
getArrayOfSimpleNumbers
andsort
are not descriptive - Code decomposition to mentioned two functions in not optimal
- Eratosthenes algorithm do not expect use of
array.sort
- I prefer loop, not recursion
what name will be preferred.
нд, 23 вер. 2018 о 14:36 Timur Shemsedinov <[email protected]> пише:
… ***@***.**** requested changes on this pull request.
Now we can start with code refactoring:
- Names getArrayOfSimpleNumbers and sort are not descriptive
- Code decomposition to mentioned two functions in not optimal
- Eratosthenes algorithm do not expect use of array.sort
- I prefer loop, not recursion
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AWHrv6pi6kbh_PxKSDubjCWZ5t2DU3OOks5ud3IqgaJpZM4W0zoO>
.
|
We can put it in |
I've already done it |
No description provided.