Apply a callback to an array: Difference between revisions

m
Line 280:
 
=={{header|D}}==
<d>U[] map(T, U)(T[] array, U delegate(T) dg) {
auto result = new U[array.length];
{
auto result = new U[array.length];
foreach (index, element; array)
result[index] = dg(element);
return result;
}
void main() {
writefln(
{
[1, 2, 3, 4, 5].map( (int i) { return i+5; } )
writefln(
);
[1, 2, 3, 4, 5].map(
}</d>
(int i) { return i+5; }
)
);
}
 
=={{header|E}}==
Anonymous user