Logo

Programming-Idioms

Set b to true if the lists p and q have the same size and the same elements, false otherwise.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
  if (size(p,1) /= size(q,1)) then
    b = false
  else
    b = all (p == q)
  end if
import "slices"
b := slices.Equal(p, q)
import java.util.ArrayList;
boolean b = p.size() == q.size();

if(b) {
	for(T item : p) {
		if(q.contains(item) == false) {
			b = false;
			break;
		}
	}
	
	if(b) {
		for(T item : q) {
			if(p.contains(item) == false) {
				b = false;
				break;
			}
		}
	}
}
classes
  b := (p.count = q.count);
  if b then for i := 0 to p.count-1 do 
    if (p.items[i] <> q.items[i]) then
    begin
      b := false;
      break;
    end;
use v5.10.1;
no warnings 'experimental::smartmatch';
$b = @array1 ~~ @array2;
use v5.10;
use smart::match;
my $b = \@array1 |M| \@array2;
use v5.10;
use strict;
sub lcomp {
    my ($a, $b) = @_;

    return 0 if ( @$a != @$b ); # lengths different

    my $matched = 1;
    for (my $i=0; $i < @$a; $i++) {
        return 0 unless $a->[$i] == $b->[$i];
    }

    return 1;
}
use Data::Compare;
$b = Compare( \@p, \@q );
b = p == q
b = p == q
b = p == q;