Skip to content

added GridGetX and GridGetY #222

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

Merged
merged 5 commits into from
Jul 7, 2020
Merged

Conversation

TangibleDream
Copy link
Contributor

@TangibleDream TangibleDream commented Jul 4, 2020

Welcome to JavaScript community

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 its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Copy link
Member

@ruppysuppy ruppysuppy left a comment

Choose a reason for hiding this comment

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

I didn't quite get the problem, could you explain it in detail?

@TangibleDream
Copy link
Contributor Author

@ruppysuppy This isn't an issue, It's a math contribution. GridGetX() and GridGetY(). returns x/y coordinates for an element in a two dimensional array. x and y coordinates are sometimes superior in grid calculations.

Let's say for instance you had an array of 10 by 10 or 100, elements and you wanted to find the shortest distance between element 3, and element 49. In this case coding out a function to return the distance without finding x and y for both elements I found to be painful. If you first find x and y, where 3 becomes 4,1 and 49 becomes 10,5, you can find distance by first subtracting x from x and y from y this returns 6,4 or -6,-4. Next apply absolute value to assure the results are positive, last choose the maximum value of the set, or 6.

I 'm sure there are other applications for desiring x and y from 2 dim arrays.

Screen Shot 2020-07-05 at 7 42 44 PM

Screen Shot 2020-07-05 at 7 45 24 PM

@ruppysuppy
Copy link
Member

Ok, but since I don't have write permissions, so someone else with the permission has to review your code too

@itsvinayak
Copy link
Member

@TangibleDream, there are few things

  • Here you have made two different files for the same type of algorithm, it would be better if we create a single class or two different functions in the same file named as " GridGet".

  • You explained the algorithm very well in the comment section of this PR, please add a well define explanation of algorithm as a comment in GridGet.js file ( as a comment )

thank you for the contribution,
@itsvinayak

Copy link
Member

@itsvinayak itsvinayak left a comment

Choose a reason for hiding this comment

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

please don't edit DIRECTORY.md, it is automatically generated by GitHub actions

@itsvinayak itsvinayak added the changes required This pull request needs changes label Jul 6, 2020
@TangibleDream TangibleDream requested a review from itsvinayak July 7, 2020 01:05
@itsvinayak itsvinayak merged commit 5150909 into TheAlgorithms:master Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required This pull request needs changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants