Created
October 28, 2017 14:23
-
-
Save dance2die/067a741bca0d2bce5024567e05eb8e2a to your computer and use it in GitHub Desktop.
Parse functionally.
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
public static int[] Parse(string data) | |
{ | |
var result = new List<int>(); | |
var commands = new Dictionary<char, Func<int, int>> | |
{ | |
{'i', n => ++n }, | |
{'d', n => --n }, | |
{'s', n => n * n }, | |
{'o', n => { result.Add(n); return n; } } | |
}; | |
var value = 0; | |
data.Select(c => value = commands[c](value)).ToList(); | |
return result.ToArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment