Questions tagged [closest]

Closest is being the nearest to a number, object, quantity etc.

Given a number of objects, the closest 2 objects would be those that the between them is the shortest.

561 questions
4
votes
1 answer

jquery find the closest element

Is there a jQuery function that combines the upward-looking closest() or parents() and the downward looking children() function? For example:
d-_-b
  • 21,536
  • 40
  • 150
  • 256
4
votes
2 answers

How select a closest element (must not be a parent of this) using jQuery?

Assume an html document:
  • aaa
  • bbb ...
    ... …
    static
    • 8,126
    • 15
    • 63
    • 89
    4
    votes
    1 answer

    Use jquery closest() to find closest element with a known sibling

    I am trying to use the jquery closest command to find a particular element based on if the element has a particular sibling. I have been playing with different selectors but haven't been able to find one yet that does what I want. So for example, if…
    bbeaudet
    • 43
    • 2
    4
    votes
    2 answers

    Remove closest empty siblings

    Let's say I have the following markup:

    not empty

    not empty

    // more content inside

    <-- whitespace, also removed

    not empty

    How do I remove the empty

    tags…

    qwerty
    • 5,166
    • 17
    • 56
    • 77
    4
    votes
    2 answers

    Jquery selecting closest checkbox inbox not working

    I have a treelist containing multiple levels of checkboxes and I am trying to get the parent checkbox to show as 'checked' when any of children checkboxes are clicked. For some reason this is not working and it's killing me. JAVASCRIPT $(function()…
    silvster27
    • 1,916
    • 6
    • 30
    • 44
    3
    votes
    2 answers

    find closest class

    I want to find a closest class of the given object. My markup looks like this:
    Leon van der Veen
    • 1,652
    • 11
    • 42
    • 60
    3
    votes
    2 answers

    Finding the closest number in a Binary Tree to a given target

    I have a very simple Binary Tree class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None root = TreeNode(8) root.left = TreeNode(5) root.right = TreeNode(14) root.left.left =…
    lukasz21
    • 59
    • 5
    3
    votes
    2 answers

    Closest element to a value (Elementwise, numpy array)

    I used to use min([a, b], key=lambda x:abs(x-x0)) to find which of a and b are the closest to x0. a = 1 b = 2 x0 = 1.49 print(min([a, b], key=lambda x:abs(x-x0))) # >>> 1 Now, a and b are numpy arrays with an arbitrary number of dimensions. I would…
    Liris
    • 1,399
    • 3
    • 11
    • 29
    3
    votes
    2 answers

    Find closest index of array using javascript

    I have the following function: (function(){ function closest (num, arr) { var curr = arr[0]; var diff = Math.abs (num - curr); for (var val = 0; val < arr.length; val++) { var newdiff = Math.abs (num -…
    bakhshi
    • 33
    • 1
    • 4
    3
    votes
    2 answers

    Detect if method closest () is supported

    I would like to find out if the method closest () is supported and if necessary (IE 11) use an alternative in the following form: ancestor = ('closest' in document.documentElement) ? element.closest (selector) : element.parentElement; The consoles…
    Janek
    • 53
    • 5
    3
    votes
    2 answers

    find the value pair in 2 sorted arrays (1 value from each array) where the sum is closest to a target value

    The original question has a list of unsorted list of 2 integers. To simplify this problem let's just consider the input is 2 sorted arrays of integers and an integer target. Value pair can repeat if there are more than 1 solution pair. For example:…
    Shawn
    • 43
    • 4
    3
    votes
    2 answers

    MySQL: Replace a column's values with values in a new table that are closest

    I have two tables like so: Table1 (ID, Kilometers, Depth) Table2 (ID, Kilometers, Depth) Sample Data: Table 1 1, 0.001, 10 2, 0.002, 11 3, 0.003, 11 Table 2 1, 0.001, 10 2, 0.003, 12 3, 0.004, 15 I need to replace the depth in table 1 with the…
    Simon
    • 9,197
    • 13
    • 72
    • 115
    3
    votes
    3 answers

    Find n closest non-NA values to position t in vector

    This is probably a simple question for those experienced in R, but it is something that I (a novice) am struggling with... I have two examples of vectors that are common to the problem I am trying to solve, A and B: A <-…
    thatWaterGuy
    • 315
    • 3
    • 12
    3
    votes
    3 answers

    php Closest minor number in array

    I have an array, for example (it can be anything, but it's already ordered): array(1,7, 12, 18, 25); I need to find what number is the closest to that array. Taking the above array: $needle = 11; The number in array i want to retrieve is 7. The…
    user538927
    • 33
    • 3
    3
    votes
    2 answers

    Mapping dict keys to column of pandas dataframe if they're close

    I'm working with probabilities that correspond to certain categories and I would like to map them to the categories of interest in a new column of a pandas DataFrame. I would normally use pandas.Series.map for such a task but the probabilities…
    p-robot
    • 4,652
    • 2
    • 29
    • 38