A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
9
Task/Filter/D/filter-1.d
Normal file
9
Task/Filter/D/filter-1.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import std.algorithm;
|
||||
|
||||
void main() {
|
||||
immutable data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
|
||||
auto evens = data.filter!(x => x % 2 == 0)(); // lazy
|
||||
|
||||
assert(evens.equal([2, 4, 6, 8, 10]));
|
||||
}
|
||||
10
Task/Filter/D/filter-2.d
Normal file
10
Task/Filter/D/filter-2.d
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import tango.core.Array, tango.io.Stdout;
|
||||
|
||||
void main() {
|
||||
auto array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
|
||||
// removeIf places even elements at the beginnig of the array and returns number of found evens
|
||||
auto evens = array.removeIf( ( typeof(array[0]) i ) { return (i % 2) == 1; } );
|
||||
Stdout("Evens - ")( array[0 .. evens] ).newline; // The order of even elements is preserved
|
||||
Stdout("Odds - ")( array[evens .. $].sort ).newline; // Unlike odd elements
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue