Any ideas what ????
should be? Is there a built in? What would be the best way to accomplish this task?
(def v ["one" "two" "three" "two"]) (defn find-thing [ thing vectr ] (????)) (find-thing "two" v) ; ? maybe 1, maybe '(1,3), actually probably a lazy-seq
Vector Indexing, or vector index notation, specifies elements within a vector. Indexing is useful when a MATLAB program only needs one element of a series of values. Indexing is often used in combination with repetition structures to conduct the same process for every element in an array.
Indexing works on Vectors, So just Acces it by using index.
int index = 0; for (auto const& element : myVec){ if(distance(element->position(), p) < d){ i = index; // the index of the current element } index++ ... Show activity on this post. &element - &myVec[0] should do the trick for container with continuous data (as std::vector ).
Built-in:
user> (def v ["one" "two" "three" "two"]) #'user/v user> (.indexOf v "two") 1 user> (.indexOf v "foo") -1
If you want a lazy seq of the indices for all matches:
user> (map-indexed vector v) ([0 "one"] [1 "two"] [2 "three"] [3 "two"]) user> (filter #(= "two" (second %)) *1) ([1 "two"] [3 "two"]) user> (map first *1) (1 3) user> (map first (filter #(= (second %) "two") (map-indexed vector v))) (1 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With