Whats a more efficient way to do the same thing that the next line of code is doing:
X = ["Please", "Thx", "Hello", "World"]
findfirst(k->occursin('H',k)==true,X)
So basically i'm trying to find the first element of the array X that has the uppercase letter H, so in the example the output is 3, but is there a more efficient way of doing this?
== true(but it will not affect the performance).containsand make it look a bit nicer :findfirst(contains('H'),X)Xis a constant or does not change too much at runtime, then you can optimize this a bit (especially ifXis bigger in practice).containsit's faster, based on the answer below, andXit could be bigger, my code finds chemical elements in ecuations, so i have to iterate over'H'to find diferent elements in the arrayX(which contains the ecuations).