-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.Filter.pas
52 lines (41 loc) · 1017 Bytes
/
Example.Filter.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
unit Example.Filter;
interface
procedure Filter;
procedure FilterNumbers;
implementation
uses
System.SysUtils,
Utils;
procedure Filter;
var
Fruta: String;
Frutas: TArray<String>;
FrutasComB: TArray<String>;
begin
Frutas := TArray<String>.Create('Uva', 'Kiwi', 'Banana', 'Abacate', 'Limão', 'Laranja');
FrutasComB := TUtil.Filter<String>(Frutas, function (Fruta: String): Boolean
begin
Result := Fruta.Contains('b') or Fruta.Contains('B');
end);
WriteLn('Frutas que contém a letra "b"');
for Fruta in FrutasComB do
Write(Fruta + ', ');
ReadLn;
end;
procedure FilterNumbers;
var
Numero: Integer;
Numeros: TArray<Integer>;
Filtro: TArray<Integer>;
begin
//Números múltiplos de 3
Numeros := TArray<Integer>.Create(1, 3, 4, 5, 6, 14, 15, 17, 22, 23, 25, 32);
Filtro := TUtil.Filter<Integer>(Numeros, function (Numero: Integer): Boolean
begin
Result := (Numero mod 3 = 0);
end);
for Numero in Filtro do
Write(Numero.ToString + ', ');
ReadLn;
end;
end.