typewise sorting comparison fn