[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Finding the first element that meets a condition

From: Brett Green
Subject: Finding the first element that meets a condition
Date: Tue, 10 Mar 2020 14:00:02 -0400

Hello all,

I have a sorted list of values and would like to find the index of the first element greater than some cutoff size. For example

min_val = 0.3;
arr = [.4, .8, .23, .19, .37];
arr_sorted = sort(arr);
index = find_first(arr_sorted,min_val);

Is there a better way to do this than a for loop? "find" would pull out every value that meets this condition and that would waste effort. On the other hand, I could use a while loop, but I would like to avoid looping if better methods exist.

first_index = 1;
first_index += 1;

- Brett Green

reply via email to

[Prev in Thread] Current Thread [Next in Thread]