Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4031868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:39:03+00:00 2026-05-20T11:39:03+00:00

I have one point (hereafter referred to as the original point) on a grid,

  • 0

I have one point (hereafter referred to as the original point) on a grid, say for example, [3, 3].

I also have a set of points that are in the same horizontal and vertical lines as the original point, say, [[3,1],[3,2],[3,4],[7,3],[8,3]].

I want some function that will return an array of at most four points: the points closest to the original point in each direction (i.e. left, right, above, below). With the example above, it would return,

[[3,2],[3,4],[7,3]]

because [3,2] is the closest point on the left, [3,4] is the closest point on the right, [7,3] is the closest point above, and there are no points below. (Order of direction is not important.)

Is there an elegant and reasonably concise way to do this, using Javascript/JQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:39:03+00:00Added an answer on May 20, 2026 at 11:39 am

    I don’t know JavaScript, but the following algorithm would be very simple, if you can formulate it with JavaScript.

    Let (X0, Y0) be the original point.

    Iterate through the array, [(X1, Y1), ..., (XN, YN)], and keep account of the minimum values of

    R = Xi – X0 > 0

    and

    L = X0 – Xi > 0

    as you proceed.
    At the end of the iteration these values give you the closest points, i.e., X0 + R
    and X0 - L.

    Do a similar iteration on the vertical line of points.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application I am working on that at one point needs
I have a VB.NET Windows Forms project that at one point paints text directly
So I have a git repository that i pulled at one point and that
I have one table that stores values with a point in time: CREATE TABLE
I have a ASP.NET app that at one point generates a PDF file and
I have one not understood point In MVC pattern. Please help understood. for example
I have one line (two point (x,y) (x1,y1)) and a rectangle with focus point
At one point of time, I have to terminate my application developed in Delphi
I have an ubuntu server with mysql installed, at one point I saw the
I am connecting to a third-party end point via WCF and I have one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.