Difference between revisions of "KeepIf Command"
From GeoGebra Manual
m |
Noel Lambert (talk | contribs) |
||
Line 1: | Line 1: | ||
<noinclude>{{Manual Page|version=5.0}}</noinclude>{{command|logical}} | <noinclude>{{Manual Page|version=5.0}}</noinclude>{{command|logical}} | ||
− | ; KeepIf[ <Condition>, | + | ; KeepIf[ <Condition>, <List> ]: Creates a new list that only contains those elements of the initial list that fulfil the condition. |
: {{Example|1=<code>KeepIf[x<3, {1, 2, 3, 4, 1, 5, 6}]</code> returns the new list ''{1, 2, 1}''.}} | : {{Example|1=<code>KeepIf[x<3, {1, 2, 3, 4, 1, 5, 6}]</code> returns the new list ''{1, 2, 1}''.}} | ||
:{{note|1=For list of numbers arbitrary condition may be used. For list of other objects one can use only conditions of the form <code>x==constant</code> or <code>x!=constant</code>.}} | :{{note|1=For list of numbers arbitrary condition may be used. For list of other objects one can use only conditions of the form <code>x==constant</code> or <code>x!=constant</code>.}} | ||
− | ; KeepIf[ <Condition>, <Variable>, | + | ; KeepIf[ <Condition>, <Variable>, <List> ] |
: This syntax allows a more flexible condition. | : This syntax allows a more flexible condition. | ||
: {{Example|1=For Points ''P, Q, R'' <code>KeepIf[x(A) < 3, A, {P, Q, R}]</code> will filter the points whose ''x''-coordinate is less than ''3'' out of the list. The variable ''A'' is replaced in turn with ''P'' then ''Q'' then ''R'' for the check.}} | : {{Example|1=For Points ''P, Q, R'' <code>KeepIf[x(A) < 3, A, {P, Q, R}]</code> will filter the points whose ''x''-coordinate is less than ''3'' out of the list. The variable ''A'' is replaced in turn with ''P'' then ''Q'' then ''R'' for the check.}} |
Revision as of 08:14, 23 August 2015
- KeepIf[ <Condition>, <List> ]
- Creates a new list that only contains those elements of the initial list that fulfil the condition.
- Example:
KeepIf[x<3, {1, 2, 3, 4, 1, 5, 6}]
returns the new list {1, 2, 1}.
- Note: For list of numbers arbitrary condition may be used. For list of other objects one can use only conditions of the form
x==constant
orx!=constant
.
- KeepIf[ <Condition>, <Variable>, <List> ]
- This syntax allows a more flexible condition.
- Example: For Points P, Q, R
KeepIf[x(A) < 3, A, {P, Q, R}]
will filter the points whose x-coordinate is less than 3 out of the list. The variable A is replaced in turn with P then Q then R for the check.