Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 3/functional_filter.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ void main(){
// Loop style
// A little better with foreach loop
auto words = ["hello", "world", "dlang", "c++", "java"];
int coolLangauges = 0;
int coolLanguages = 0;
foreach(element ; words){
if(element=="dlang"){
coolLangauges++;
coolLanguages++;
}
}
writeln("Cool langauges found: ",coolLangauges);
writeln("Cool languages found: ",coolLanguages);

// Functional-style

auto words2 = ["hello", "world", "dlang", "c++", "java"];
auto result = words.filter!(a=> a.indexOf("dlang") >=0).count;
writeln("Cool langauges found: ",result);
writeln("Cool languages found: ",result);

}