JavaScript
JavaScript copied to clipboard
Reduce code repetition
We have now successfully added guidelines for importing and using algorithms in this repository, inside other algorithms. This has been done to reduce code repetition and uphold code quality. Some functions do implement their own versions of data structures and helper functions, as previously, algorithms were supposed to be completely self contained. This issue initiates a search and fix so that all functions and data structures which can be imported in an algorithm should be imported.
Also as an addition to the topic, this initiative should also weed out bad code, i.e.:
- Code which does not follow the contributing guidelines.
- Code with a bad implementation.
- Bad Code in general.
- Complicated operations without comments.
@lvlte @defaude Any of you interested in working on this?
Yep sure, I will take a look next week.
Hey, I wanna do it. Please assign it to me.
@littlefermatlives Please open a pull request and do the changes. I will review it.
If anyone finds some of those and either doesn't want to work on them or don't have to knowledge of the function, feel free to share here so others can do it.
I feel like it would also be a good idea for someone to make a checklist on those files that have been throughly checked for these and don't need any more review.
Hello, We are working on some improvements to this issue.
/Students from Royal Institute of Technology
@benronkth If you have any questions or face any issues, feel free to ask in this thread.
There is a function called rotate (angleInRadians) in two files, namely:
- Data-Structures\Vectors\Vector2.js
/**
* Vector rotation (see https://en.wikipedia.org/wiki/Rotation_matrix)
*
* @param angleInRadians The angle in radians by which to rotate the vector.
* @returns The rotated vector.
*/
rotate (angleInRadians) {
const ca = Math.cos(angleInRadians)
const sa = Math.sin(angleInRadians)
const x = ca * this.x - sa * this.y
const y = sa * this.x + ca * this.y
return new Vector2(x, y)
}
- Recursive\KochSnowflake.js
/**
* Vector rotation (see https://en.wikipedia.org/wiki/Rotation_matrix)
*
* @param angleInDegrees The angle by which to rotate the vector.
* @returns The rotated vector.
*/
rotate (angleInDegrees) {
const radians = angleInDegrees * Math.PI / 180
const ca = Math.cos(radians)
const sa = Math.sin(radians)
const x = ca * this.x - sa * this.y
const y = sa * this.x + ca * this.y
return new Vector2(x, y)
}
As you see they should be doing the same operation but there is a conversion happening in the second file const radians = angleInDegrees * Math.PI / 180
. Not having this line results in a test fail in Recursive\test\KochSnowflake.test.js. Which function should be kept (or renamed)?
Since the second one is first converting to radians and then essentially running the first function, we can rewrite the second one in terms of the first.
Is this issue open yet?
Is this issue open yet?
This issue is obviously still open?
This issue is obviously still open?
Then can u assign it to me?
thanks!
Can I be assigned this issue please?
Sure, but you have to agree with @201B153 what each of you wants to work on so that you don't end up doing the same work twice.
it's a huge thing so i don't think there is any issue in working together
Alright, that’ll be nice, @201B153 working together would be a great pleasure
it's a huge thing so i don't think there is any issue in working together
@201B153 you can dm me on twitter, @abdulfrfr is my handle
I will do it please assign it to me
Just open a pr not need for assignment. This is a broad issue and will benefit from multiple contributors.
Hi! please assign me this issue.
Hi! please assign me this issue.
Please read the comment right above your comment. I'm clearing the assignees to make this clear.
This is my first time contributing to open source. So can you please assign this to me?
This is my first time contributing to open source. So can you please assign this to me?
Just start working on it right away; there is a very small chance you'll end up colliding with the PR of another contributor, doing the same work twice. See this comment.
Locking conversation due to repeated unnecessary assignment pleas. Anyone interested in working on this issue should just start doing that without waiting for being assigned. This is a broad issue and will benefit from multiple contributors. It is unlikely that your work will collide with someone else's.