Created
June 22, 2011 20:46
-
-
Save brandonc/1041133 to your computer and use it in GitHub Desktop.
Reduce an array using regex in C# and ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
namespace Program | |
{ | |
class XFiles | |
{ | |
static int Main(string[] argv) | |
{ | |
string[] names = { "Mark", "Richard", "Fox", "Scully" }; | |
var r = new Regex("(Fox|Scully)"); | |
var xfiles = names.Where(name => r.IsMatch(name)).ToArray(); | |
Console.WriteLine("Everyone: {0}", String.Join(", ", names)); | |
Console.WriteLine(" X-Files: {0}", String.Join(", ", xfiles)); | |
return 0; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
names = ["Mark", "Richard", "Fox", "Scully"] | |
xfiles = names.select do |name| | |
name =~ /(Fox|Scully)/ | |
end | |
puts "Everyone: #{names.join(", ")}" | |
puts " X-Files: #{xfiles.join(", ")}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stopwatch 100 executions of each using simple shell script (windows / mingw32 bash)
Ruby
C#