Compare two arrays in a wrangle SOP if statement
5979
3
1
Farmfield
Member
65 posts
Joined: Sept. 2014
Offline
July 11, 2016 10:24 a.m.
How do I compare two arrays in a if? Do I need to iterate the comparison in a foreach or is there an easier way?
float maxdist = 0.5; int maxpoints = 15; int current[] = pcfind(0, "P", @P, maxdist, maxpoints); int orig[] = pcfind(1, "P", @P, maxdist, maxpoints); // Well, this doesn't work... // // i@group_broken = (current[] != orig[]) ? 1: 0; float maxdist = 0.5; int maxpoints = 15; int current[] = pcfind(0, "P", @P, maxdist, maxpoints); int orig[] = pcfind(1, "P", @P, maxdist, maxpoints); // ...or this... // // i[]@current = current; // i[]@orig = orig; // // i@group_broken = (i[]@current != i[]@orig) ? 1: 0;
Edited by Farmfield - July 11, 2016 10:33:01
July 11, 2016 12:19 p.m.
not 100% sure , but I assume if you need to test the arrays are identical to each other you would need to loop over and compare each element you can break the loop as soon as one of the values fails the comparison test something like this: int tester = 1; int count = 0; if( len(array1) == len(array2) { while( tester ) if( count = len(array1 ) ) tester = 0; if( array1 == array2 ) count += 1; else tester = 0; }
Farmfield
Member
65 posts
Joined: Sept. 2014
Offline
July 14, 2016 9:56 a.m.
Wow, I thought I had it set so I get a mail when someone replies - apparently not. Much appreciated, I'll check it out, see if it works for the setup I was messing with.
July 14, 2016 11:25 a.m.
I have noticed the same thing with not receiving notifications
I just ran a quick test of my previous slap code and noticed a few errors, here is a working example run in a detail wrangle:
i[]@ar1 = {0,1,2,3,4}; i[]@ar2 = {0,1,2,3,5}; int tester = 1; i@result = 0; int count = 0; if( len(@ar1) == len(@ar2)) { while(tester) { if( count == len(@ar1) ) tester = 0; if( @ar1[count] == @ar2[count] ) { count += 1; @result = 1; }else{ tester = 0; @result = 0; } } }else{ tester = 0; } the detail attr result will return 0 if the array is different and return 1 if they are equal
it looks like my code got munged a bit…all the brackets got removed…fixed it now
Edited by sidenimjay - July 14, 2016 11:28:57