X Tutup
The Wayback Machine - https://web.archive.org/web/20200921160920/https://github.com/TheAlgorithms/Javascript/pull/222
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

added GridGetX and GridGetY #222

Merged
merged 5 commits into from Jul 7, 2020
Merged

Conversation

@TangibleDream
Copy link
Contributor

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
Contributor

ruppysuppy left a comment

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

@TangibleDream
Copy link
Contributor Author

TangibleDream commented Jul 6, 2020

@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
Contributor

ruppysuppy commented Jul 6, 2020

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

itsvinayak commented Jul 6, 2020

@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 left a comment

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

@TangibleDream TangibleDream requested a review from itsvinayak Jul 7, 2020
@itsvinayak itsvinayak merged commit 5150909 into TheAlgorithms:master Jul 7, 2020
2 checks passed
2 checks passed
build (14.x)
Details
LGTM analysis: JavaScript No new or fixed alerts
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.
X Tutup