Possible Duplicate:
How to avoid returning a Null if there is no “else” condition in an If contruct
I know there are other ways to solve this problem. Just because I'm curious I tried:
Map[If[# == 1, , #] &, {2, 1, 3, 1, 4}]
This should return a list without the value 1, because when the statement is true it should do nothing. The solution should be:
{2,3,4}
and not
{2,Null,3,Null,4}
Why is it not working as I expect?
DeleteCases[{2, 1, 3, 1, 4},1]
$\endgroup$Map[If[# == 1, Unevaluated[Sequence[]], #] &, {2, 1, 3, 1, 4}]
in that case :) $\endgroup$