Are there any quick ways to quickly search for an matched search in a vector or an array and return the index of that element?
Depending on what you are doing you might be able to use a Map instead of a Vector for rapid access to stored information.
Regards, AB
Thanks! After thinking for a while, I'm actually going to stick with the vectors since most of my code revolves around that now. I do have another question though. I made this function to search within vectors:
function searchVector(vector, searchterm) {
var index = DOpus.Create.Vector();
for (var n=0; n<vector.length; n++) {
if (String(vector(n)) == searchterm) {index.push_back = n;}
}
return index;
}
and this is the code part that will be using it:
var index = searchVector(ReOps_data_copy, ReOps_dest);
if (index != null) {for (var i=index.length-1; i>-1; i=i-1) {ReOps_data_move.erase(index(i));}}
ReOps_data_copy is another vector that stores a list of paths such as "E:\Desktop". ReOps_dest is simply a string with the path that came from GetCopyQueueNameData.dest that's part of the function OnGetCopyQueueName(GetCopyQueueNameData). When I tried comparing the value stored within ReOps_data_copy and the value that came from GetCopyQueueNameData.dest, they never match. I had to convert the item in ReOps_data_copy to a string value before it matches up. I don't understand that part. Type mismatch?
Sounds like a type mismatch. You can use code like this..
DOpus.output(typeof var1);
DOpus.output(typeof var2);
..to see the type of both comparison variables.
Regards, AB
Oddly enough they're both objects. So they should be the same then. I also tried the "===" to compare directly without any conversions but I got the same results that both are different. Very odd...
Objects are seldom identical unless one is cloned from the other. Converting object properties to strings is a common precursor to performing a comparison.
Not having been grounded in OO programming, which wasn't around in my far off youthful days , I am still getting my head around this stuff. It eventually all starts to make sense......
Regards, AB
Ah thanks! That explains everything. I will stringified both then and be done with that part.
Starting to make sense? After lots of torture dealing with it, right? And I'm still early in the torture so I have a lot to look forward to hahaha.