Bring over permission level from WordPress MemberPress

You could try creating arrays for the groups you wish to add and remove. For each condition you check, add to the arrays. Something like the code below could be used inside of your function.

//...

$groups_to_add = [];
$groups_to_remove = [];

if ( /* some condition */ ) {
    $groups_to_add[] = 'group_one'; // $array[] = 'element' adds 'element' to the array.
    } else {
    $groups_to_remove[] = 'group_one';
}

if ( /* another condition */ ) {
    $groups_to_add[] = 'group_two';
    } else {
    $groups_to_remove[] = 'group_two';
}

//...

$params['add_groups'] = join( ',', $groups_to_add ); // Create a string from the array, with ',' as the separator.
$params['remove_groups'] = join( ',', $groups_to_remove );

return $params;

Make sure you are calling join() with no spaces in the separator parameter (',').