Skip to content
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

algorithm class: rectangle #1340

Closed
wants to merge 2 commits into from
Closed

algorithm class: rectangle #1340

wants to merge 2 commits into from

Conversation

lynnmeanslight
Copy link

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.


const rectangle = new Rectangle(4, 2)

test('The area of a rectangle with length equal to 4 and width equal to 2', () => {
Copy link
Collaborator

@appgurueu appgurueu Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are trivial; they don't need redundant names.

return Math.sqrt(Math.pow(this.length, 2) + Math.pow(this.width, 2))
}

isSquare = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't isSquare = () => this.length === this.width work?

}

diagonalLength = () => {
return Math.sqrt(Math.pow(this.length, 2) + Math.pow(this.width, 2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use Math.pow when JS has ** for exponentiation?


export default class Rectangle {
constructor (length, width) {
this.length = length
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is usually called "height"

Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty trivial. @raklaptudirm thoughts on accepting trivial algorithms / data structures?

@raklaptudirm
Copy link
Member

I would say only to allow trivial algorithm implementations if they are able to showcase good usage of a large range of language features. This implementation doesn't seem to do that, and imo, has little educational value. I am in favor of closing this pr.

@lynnmeanslight
Copy link
Author

I saw the class "circle" and I wanted to implement for rectangle too. I can fixe the width to the height. Could you please consider to be merged?

@appgurueu
Copy link
Collaborator

appgurueu commented Jul 22, 2023

I agree with rak that this is pretty trivial and has little educational value. You could consider:

  1. Using more language features, such as getters
  2. Making the class more useful by adding x and y fields, then implementing rectangle-rectangle intersection / collision and "rectangle contains point" queries

The latter is needed very often in game dev. It isn't terribly difficult to implement, but it is very useful and not as trivial as perimeter or area of a rectangle.

@lynnmeanslight lynnmeanslight closed this by deleting the head repository Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants