JavaScript icon indicating copy to clipboard operation
JavaScript copied to clipboard

Reduce code repetition

Open raklaptudirm opened this issue 3 years ago • 25 comments

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.

raklaptudirm avatar Oct 08 '21 08:10 raklaptudirm

@lvlte @defaude Any of you interested in working on this?

raklaptudirm avatar Oct 21 '21 14:10 raklaptudirm

Yep sure, I will take a look next week.

lvlte avatar Oct 21 '21 17:10 lvlte

Hey, I wanna do it. Please assign it to me.

littlefermatlives avatar Oct 22 '21 11:10 littlefermatlives

@littlefermatlives Please open a pull request and do the changes. I will review it.

raklaptudirm avatar Oct 22 '21 11:10 raklaptudirm

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.

RenatoLopes771 avatar Oct 27 '21 23:10 RenatoLopes771

Hello, We are working on some improvements to this issue.

/Students from Royal Institute of Technology

benronkth avatar Mar 01 '22 09:03 benronkth

@benronkth If you have any questions or face any issues, feel free to ask in this thread.

raklaptudirm avatar Mar 01 '22 14:03 raklaptudirm

There is a function called rotate (angleInRadians) in two files, namely:

  1. 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)
  }
  1. 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)?

benronkth avatar Mar 03 '22 14:03 benronkth

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.

raklaptudirm avatar Mar 03 '22 14:03 raklaptudirm

Is this issue open yet?

mstomar698 avatar Sep 29 '22 17:09 mstomar698

Is this issue open yet?

This issue is obviously still open?

appgurueu avatar Sep 29 '22 18:09 appgurueu

This issue is obviously still open?

Then can u assign it to me?

mstomar698 avatar Sep 30 '22 13:09 mstomar698

thanks!

mstomar698 avatar Sep 30 '22 13:09 mstomar698

Can I be assigned this issue please?

abdulfrfr avatar Oct 01 '22 14:10 abdulfrfr

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.

appgurueu avatar Oct 01 '22 14:10 appgurueu

it's a huge thing so i don't think there is any issue in working together

mstomar698 avatar Oct 01 '22 14:10 mstomar698

Alright, that’ll be nice, @201B153 working together would be a great pleasure

abdulfrfr avatar Oct 01 '22 15:10 abdulfrfr

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

abdulfrfr avatar Oct 01 '22 15:10 abdulfrfr

I will do it please assign it to me

Akash7649 avatar Oct 10 '22 13:10 Akash7649

Just open a pr not need for assignment. This is a broad issue and will benefit from multiple contributors.

raklaptudirm avatar Oct 13 '22 11:10 raklaptudirm

Hi! please assign me this issue.

Amit-Sagar avatar Oct 15 '22 17:10 Amit-Sagar

Hi! please assign me this issue.

Please read the comment right above your comment. I'm clearing the assignees to make this clear.

appgurueu avatar Oct 15 '22 18:10 appgurueu

This is my first time contributing to open source. So can you please assign this to me?

aakash176 avatar Dec 19 '22 14:12 aakash176

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.

appgurueu avatar Dec 19 '22 16:12 appgurueu

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.

raklaptudirm avatar Dec 19 '22 16:12 raklaptudirm