trackler 2.2.1.43 → 2.2.1.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/lens-person/description.md +1 -1
  4. data/problem-specifications/exercises/palindrome-products/description.md +5 -12
  5. data/problem-specifications/exercises/pascals-triangle/canonical-data.json +1 -7
  6. data/tracks/c/exercises/meetup/src/example.c +64 -60
  7. data/tracks/c/exercises/meetup/src/example.h +2 -2
  8. data/tracks/c/exercises/meetup/test/test_meetup.c +4 -4
  9. data/tracks/cfml/config.json +179 -169
  10. data/tracks/cfml/exercises/markdown/.meta/HINTS.md +0 -0
  11. data/tracks/cfml/exercises/markdown/Markdown.cfc +121 -0
  12. data/tracks/cfml/exercises/markdown/MarkdownTest.cfc +51 -0
  13. data/tracks/cfml/exercises/markdown/Solution.cfc +204 -0
  14. data/tracks/cfml/exercises/markdown/SolutionTest.cfc +7 -0
  15. data/tracks/cfml/exercises/markdown/TestRunner.cfc +103 -0
  16. data/tracks/cfml/exercises/markdown/box.json +8 -0
  17. data/tracks/cfml/exercises/markdown/index.cfm +37 -0
  18. data/tracks/csharp/exercises/dominoes/DominoesTest.cs +40 -45
  19. data/tracks/csharp/exercises/meetup/MeetupTest.cs +761 -83
  20. data/tracks/csharp/generators/Exercises/Dominoes.cs +33 -0
  21. data/tracks/csharp/generators/Exercises/Meetup.cs +46 -0
  22. data/tracks/csharp/generators/Output/FormattingExtensions.cs +11 -1
  23. data/tracks/csharp/generators/Output/TypesExtensions.cs +23 -0
  24. data/tracks/csharp/generators/Output/ValueFormatter.cs +70 -69
  25. data/tracks/dart/config.json +15 -3
  26. data/tracks/dart/exercises/word-count/README.md +18 -0
  27. data/tracks/dart/exercises/word-count/lib/example.dart +26 -0
  28. data/tracks/dart/exercises/word-count/lib/word_count.dart +3 -0
  29. data/tracks/dart/exercises/word-count/pubspec.lock +293 -0
  30. data/tracks/dart/exercises/word-count/pubspec.yaml +3 -0
  31. data/tracks/dart/exercises/word-count/test/word_count_test.dart +64 -0
  32. data/tracks/ecmascript/docs/INSTALLATION.md +4 -7
  33. data/tracks/elixir/exercises/hello-world/README.md +1 -26
  34. data/tracks/elixir/exercises/hello-world/example.exs +3 -7
  35. data/tracks/elixir/exercises/hello-world/hello_world.exs +3 -25
  36. data/tracks/elixir/exercises/hello-world/hello_world_test.exs +2 -13
  37. data/tracks/elixir/mix.lock +1 -1
  38. data/tracks/elm/config.json +11 -0
  39. data/tracks/elm/exercises/pascals-triangle/README.md +51 -0
  40. data/tracks/elm/exercises/pascals-triangle/Triangle.elm +1 -0
  41. data/tracks/elm/exercises/pascals-triangle/Triangle.example.elm +23 -0
  42. data/tracks/elm/exercises/pascals-triangle/elm-package.json +14 -0
  43. data/tracks/elm/exercises/pascals-triangle/package.json +14 -0
  44. data/tracks/elm/exercises/pascals-triangle/tests/Tests.elm +34 -0
  45. data/tracks/elm/exercises/pascals-triangle/tests/elm-package.json +16 -0
  46. data/tracks/fsharp/exercises/grade-school/GradeSchool.fs +2 -2
  47. data/tracks/fsharp/exercises/grade-school/GradeSchoolTest.fs +3 -2
  48. data/tracks/java/CONTRIBUTING.md +34 -0
  49. data/tracks/java/config.json +42 -6
  50. data/tracks/java/exercises/largest-series-product/src/main/java/LargestSeriesProductCalculator.java +7 -3
  51. data/tracks/java/exercises/matrix/src/main/java/Matrix.java +23 -0
  52. data/tracks/julia/config.json +11 -2
  53. data/tracks/julia/exercises/grains/README.md +33 -0
  54. data/tracks/julia/exercises/grains/example.jl +23 -0
  55. data/tracks/julia/exercises/grains/grains.jl +9 -0
  56. data/tracks/julia/exercises/grains/runtests.jl +27 -0
  57. data/tracks/lua/README.md +1 -1
  58. data/tracks/mips/exercises/octal/README.md +3 -8
  59. data/tracks/ocaml/exercises/palindrome-products/README.md +8 -14
  60. data/tracks/perl6/.travis.yml +7 -3
  61. data/tracks/perl6/bin/exercise-gen.pl6 +5 -1
  62. data/tracks/perl6/exercises/accumulate/README.md +0 -3
  63. data/tracks/perl6/exercises/accumulate/accumulate.t +9 -3
  64. data/tracks/perl6/exercises/all-your-base/README.md +1 -1
  65. data/tracks/perl6/exercises/all-your-base/all-your-base.t +23 -11
  66. data/tracks/perl6/exercises/all-your-base/example.yaml +1 -1
  67. data/tracks/perl6/exercises/allergies/README.md +0 -1
  68. data/tracks/perl6/exercises/allergies/allergies.t +22 -10
  69. data/tracks/perl6/exercises/anagram/anagram.t +22 -10
  70. data/tracks/perl6/exercises/atbash-cipher/README.md +2 -1
  71. data/tracks/perl6/exercises/atbash-cipher/atbash-cipher.t +22 -10
  72. data/tracks/perl6/exercises/binary/README.md +2 -0
  73. data/tracks/perl6/exercises/bob/bob.t +24 -11
  74. data/tracks/perl6/exercises/bob/example.yaml +2 -2
  75. data/tracks/perl6/exercises/clock/clock.t +22 -10
  76. data/tracks/perl6/exercises/flatten-array/README.md +1 -2
  77. data/tracks/perl6/exercises/flatten-array/example.yaml +1 -1
  78. data/tracks/perl6/exercises/flatten-array/flatten-array.t +23 -11
  79. data/tracks/perl6/exercises/grade-school/README.md +0 -1
  80. data/tracks/perl6/exercises/grade-school/grade-school.t +9 -3
  81. data/tracks/perl6/exercises/grains/README.md +0 -1
  82. data/tracks/perl6/exercises/grains/grains.t +22 -10
  83. data/tracks/perl6/exercises/hello-world/example.yaml +3 -3
  84. data/tracks/perl6/exercises/hello-world/hello-world.t +25 -12
  85. data/tracks/perl6/exercises/leap/README.md +1 -1
  86. data/tracks/perl6/exercises/leap/example.yaml +1 -1
  87. data/tracks/perl6/exercises/leap/leap.t +23 -11
  88. data/tracks/perl6/exercises/linked-list/README.md +10 -10
  89. data/tracks/perl6/exercises/linked-list/linked-list.t +9 -3
  90. data/tracks/perl6/exercises/luhn/README.md +7 -7
  91. data/tracks/perl6/exercises/luhn/luhn.t +22 -10
  92. data/tracks/perl6/exercises/phone-number/README.md +3 -2
  93. data/tracks/perl6/exercises/phone-number/phone-number.t +22 -10
  94. data/tracks/perl6/exercises/raindrops/raindrops.t +22 -10
  95. data/tracks/perl6/exercises/rna-transcription/rna-transcription.t +22 -10
  96. data/tracks/perl6/exercises/robot-name/robot-name.t +9 -3
  97. data/tracks/perl6/exercises/scrabble-score/README.md +3 -1
  98. data/tracks/perl6/exercises/scrabble-score/scrabble-score.t +22 -10
  99. data/tracks/perl6/exercises/space-age/README.md +2 -1
  100. data/tracks/perl6/exercises/space-age/space-age.t +22 -10
  101. data/tracks/perl6/exercises/trinary/README.md +1 -1
  102. data/tracks/perl6/exercises/word-count/README.md +1 -2
  103. data/tracks/perl6/exercises/word-count/word-count.t +22 -10
  104. data/tracks/perl6/exercises/wordy/README.md +0 -5
  105. data/tracks/perl6/exercises/wordy/wordy.t +22 -10
  106. data/tracks/perl6/templates/test.mustache +26 -15
  107. data/tracks/python/config.json +10 -0
  108. data/tracks/python/exercises/book-store/book_store.py +1 -1
  109. data/tracks/python/exercises/flatten-array/flatten_array.py +1 -1
  110. data/tracks/python/exercises/matrix/matrix.py +1 -1
  111. data/tracks/python/exercises/palindrome-products/palindrome_products.py +2 -2
  112. data/tracks/python/exercises/perfect-numbers/perfect_numbers.py +2 -2
  113. data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet.py +3 -3
  114. data/tracks/python/exercises/raindrops/raindrops.py +1 -1
  115. data/tracks/python/exercises/scale-generator/scale_generator.py +1 -1
  116. data/tracks/python/exercises/sieve/sieve.py +1 -1
  117. data/tracks/python/exercises/sublist/sublist.py +1 -1
  118. data/tracks/python/exercises/transpose/transpose.py +1 -1
  119. data/tracks/python/exercises/triangle/triangle.py +4 -1
  120. data/tracks/python/exercises/two-bucket/example.py +59 -0
  121. data/tracks/python/exercises/two-bucket/two_bucket.py +2 -0
  122. data/tracks/python/exercises/two-bucket/two_bucket_test.py +32 -0
  123. data/tracks/scheme/config.json +59 -89
  124. data/tracks/scheme/config/maintainers.json +11 -11
  125. data/tracks/sml/exercises/allergies/README.md +20 -5
  126. data/tracks/sml/exercises/allergies/allergies.sml +11 -14
  127. data/tracks/sml/exercises/allergies/example.sml +9 -9
  128. data/tracks/sml/exercises/allergies/test.sml +65 -129
  129. data/tracks/sml/exercises/allergies/testlib.sml +159 -0
  130. data/tracks/sml/exercises/hamming/README.md +21 -5
  131. data/tracks/sml/exercises/hamming/example.sml +14 -10
  132. data/tracks/sml/exercises/hamming/hamming.sml +4 -3
  133. data/tracks/sml/exercises/hamming/test.sml +55 -64
  134. data/tracks/sml/exercises/hamming/testlib.sml +159 -0
  135. data/tracks/typescript/config.json +15 -0
  136. data/tracks/typescript/exercises/linked-list/linked-list.test.ts +11 -11
  137. data/tracks/typescript/exercises/nth-prime/README.md +36 -0
  138. data/tracks/typescript/exercises/nth-prime/nth-prime.example.ts +28 -0
  139. data/tracks/typescript/exercises/nth-prime/nth-prime.test.ts +25 -0
  140. data/tracks/typescript/exercises/nth-prime/nth-prime.ts +0 -0
  141. data/tracks/typescript/exercises/nth-prime/package.json +36 -0
  142. data/tracks/typescript/exercises/nth-prime/tsconfig.json +22 -0
  143. data/tracks/typescript/exercises/nth-prime/tslint.json +127 -0
  144. data/tracks/typescript/exercises/nth-prime/yarn.lock +2305 -0
  145. data/tracks/typescript/exercises/prime-factors/README.md +1 -1
  146. data/tracks/typescript/exercises/prime-factors/prime-factors.test.ts +11 -11
  147. data/tracks/typescript/exercises/series/README.md +1 -1
  148. data/tracks/typescript/exercises/series/series.test.ts +11 -11
  149. data/tracks/typescript/img/icon.png +0 -0
  150. data/tracks/typescript/img/icon.svg +3 -8
  151. metadata +44 -2
@@ -0,0 +1,33 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+ using Generators.Input;
5
+ using Generators.Output;
6
+ using Newtonsoft.Json.Linq;
7
+
8
+ namespace Generators.Exercises
9
+ {
10
+ public class Dominoes : Exercise
11
+ {
12
+ protected override void UpdateCanonicalData(CanonicalData canonicalData)
13
+ {
14
+ foreach (var canonicalDataCase in canonicalData.Cases)
15
+ {
16
+ canonicalDataCase.UseVariablesForInput = true;
17
+ canonicalDataCase.Properties["input"] = ConvertInput(canonicalDataCase.Properties["input"]);
18
+ }
19
+ }
20
+
21
+ protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string>() { typeof(Tuple).Namespace };
22
+
23
+ private UnescapedValue ConvertInput(dynamic input)
24
+ {
25
+ var dominoes = (input as JArray).Children();
26
+
27
+ // Manually format array of ints to array of tuples since the ValueFormatter doesn't handle Tuple<int,int>[]
28
+ // Project each jtoken element to an int array, then format to a string that will create a tuple from the 2-element array (via UnescapedValues)
29
+ var tuplesStringLiteral = dominoes.Select(s => s.ToObject<int[]>()).Select(s => $"Tuple.Create({s[0]}, {s[1]})");
30
+ return new UnescapedValue($"new Tuple<int, int>[] {{ {string.Join(", ", tuplesStringLiteral)} }}");
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,46 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using Generators.Input;
4
+ using Generators.Output;
5
+ using Humanizer;
6
+
7
+ namespace Generators.Exercises
8
+ {
9
+ public class Meetup : Exercise
10
+ {
11
+ private const string ParamYear = "year";
12
+ private const string ParamMonth = "month";
13
+ private const string ParamDay = "dayofmonth";
14
+ private const string ParamSchedule = "week";
15
+ private const string ParamDayOfWeek = "dayofweek";
16
+
17
+ private const string PropertyDay = "Day";
18
+
19
+ protected override void UpdateCanonicalData(CanonicalData canonicalData)
20
+ {
21
+ foreach (var canonicalDataCase in canonicalData.Cases)
22
+ {
23
+ canonicalDataCase.Property = PropertyDay;
24
+ canonicalDataCase.UseVariableForExpected = true;
25
+ canonicalDataCase.SetConstructorInputParameters(ParamMonth, ParamYear);
26
+ canonicalDataCase.SetInputParameters(ParamDayOfWeek, ParamSchedule);
27
+
28
+ canonicalDataCase.Properties[ParamSchedule] =
29
+ new UnescapedValue($"Schedule.{((string)canonicalDataCase.Properties[ParamSchedule]).Transform(To.SentenceCase)}");
30
+ canonicalDataCase.Properties[ParamDayOfWeek] =
31
+ new UnescapedValue($"DayOfWeek.{((string)canonicalDataCase.Properties[ParamDayOfWeek]).Transform(To.SentenceCase)}");
32
+ canonicalDataCase.Expected =
33
+ $"{canonicalDataCase.Properties[ParamYear]}-{canonicalDataCase.Properties[ParamMonth]}-{canonicalDataCase.Properties[ParamDay]}";
34
+ }
35
+ }
36
+
37
+ protected override String RenderTestMethodBodyAssert(TestMethodBody testMethodBody)
38
+ {
39
+ string template = $"Assert.Equal({{{{ ExpectedParameter }}}}, {{{{ TestedValue }}}}.ToString(\"yyyy-M-d\"));";
40
+
41
+ return TemplateRenderer.RenderInline(template, testMethodBody.AssertTemplateParameters);
42
+ }
43
+
44
+ protected override HashSet<String> AddAdditionalNamespaces() => new HashSet<string> { typeof(DayOfWeek).Namespace };
45
+ }
46
+ }
@@ -1,4 +1,7 @@
1
- namespace Generators.Output
1
+ using System.Collections.Generic;
2
+ using System.Linq;
3
+
4
+ namespace Generators.Output
2
5
  {
3
6
  public static class FormattingExtensions
4
7
  {
@@ -11,5 +14,12 @@ public static string EscapeSpecialCharacters(this string s)
11
14
  .Replace("\"", "\\\"");
12
15
 
13
16
  public static string Quote(this string s) => $"\"{s}\"";
17
+
18
+ public static IEnumerable<string> AddTrailingSemicolon(this IEnumerable<string> enumerable)
19
+ {
20
+ var array = enumerable.ToArray();
21
+ array[array.Length - 1] += ";";
22
+ return array;
23
+ }
14
24
  }
15
25
  }
@@ -0,0 +1,23 @@
1
+ using System.Collections.Generic;
2
+
3
+ namespace Generators.Output
4
+ {
5
+ public static class TypesExtensions
6
+ {
7
+ public static IEnumerable<T> SliceColumn<T>(this T[,] array, int column)
8
+ {
9
+ for (var i = array.GetLowerBound(0); i <= array.GetUpperBound(0); i++)
10
+ {
11
+ yield return array[i, column];
12
+ }
13
+ }
14
+
15
+ public static IEnumerable<T> SliceRow<T>(this T[,] array, int row)
16
+ {
17
+ for (var i = array.GetLowerBound(1); i <= array.GetUpperBound(1); i++)
18
+ {
19
+ yield return array[row, i];
20
+ }
21
+ }
22
+ }
23
+ }
@@ -12,46 +12,27 @@ public static object Format(object val)
12
12
  {
13
13
  switch (val)
14
14
  {
15
- case IDictionary<string, object> dict:
16
- return string.Join(", ", dict.Values.Select(Format));
17
- case IDictionary<char, int> dict:
18
- return $"new Dictionary<char, int> {{ {string.Join(", ", dict.Keys.Select(key => $"[{Format(key)}] = {Format(dict[key])}"))} }}";
19
- case IDictionary<string, int> dict:
20
- return $"new Dictionary<string, int> {{ {string.Join(", ", dict.Keys.Select(key => $"[{Format(key)}] = {Format(dict[key])}"))} }}";
21
- case Enum enumeration:
22
- return $"{enumeration.GetType().Name}.{enumeration}";
23
- case JArray jArray:
24
- return $"new[] {{ {string.Join(", ", jArray.Select(Format))} }}";
25
- case int[,] multidimensionalArray:
26
- return multidimensionalArray.GetLength(0) > 1
27
- ? $"new[,]\r\n{{\r\n {string.Join(",\r\n ", Enumerable.Range(0, multidimensionalArray.GetUpperBound(0) + 1).Select(x => multidimensionalArray.SliceRow(x).ToNestedArray()))}\r\n}}"
28
- : "new int[,] { }";
29
- case IEnumerable<Tuple<string, object>> tuples:
30
- return $"new[] {{ {string.Join(", ", tuples.Select(Format))} }}";
31
- case Tuple<string, object> tuple:
32
- return $"Tuple.Create({tuple.Item1}, {tuple.Item2})";
33
- case string str:
34
- return str.FormatString();
35
- case IEnumerable<int> ints:
36
- return ints.Any() ? $"new[] {{ {string.Join(", ", ints)} }}" : "new int[0]";
37
- case IEnumerable<string> strings:
38
- return strings.Any() ? $"new[] {{ {string.Join(", ", strings.Select(Format) )} }}" : "new string[0]";
39
- case IEnumerable<UnescapedValue> unescapedValues when unescapedValues.Any():
40
- return $"new[] {{ {string.Join(", ", unescapedValues.Select(Format) )} }}";
41
- case double dbl:
42
- return dbl.ToString(CultureInfo.InvariantCulture);
43
- case float flt:
44
- return flt.ToString(CultureInfo.InvariantCulture);
45
- case ulong ulng:
46
- return $"{ulng}UL";
47
- case char c:
48
- return $"'{c}'";
49
- default:
50
- return val;
15
+ case string str: return str.Format();
16
+ case double dbl: return dbl.Format();
17
+ case float flt: return flt.Format();
18
+ case ulong ulng: return ulng.Format();
19
+ case char c: return c.Format();
20
+ case Enum enumeration: return enumeration.Format();
21
+ case Tuple<string, object> tuple: return tuple.Format();
22
+ case IEnumerable<int> ints: return ints.Format();
23
+ case IEnumerable<string> strings: return strings.Format();
24
+ case IEnumerable<UnescapedValue> unescapedValues when unescapedValues.Any(): return unescapedValues.Format();
25
+ case IDictionary<string, object> dict: return dict.Format();
26
+ case IDictionary<char, int> dict: return dict.Format();
27
+ case IDictionary<string, int> dict: return dict.Format();
28
+ case JArray jArray: return jArray.Format();
29
+ case int[,] multidimensionalArray: return multidimensionalArray.Format();
30
+ case IEnumerable<Tuple<string, object>> tuples: return tuples.Format();
31
+ default: return val;
51
32
  }
52
33
  }
53
34
 
54
- public static string[] FormatVariables(IReadOnlyDictionary<string, object> dict)
35
+ public static string[] FormatVariables(IReadOnlyDictionary<string, object> dict)
55
36
  => dict.Keys.SelectMany(key => FormatVariable(dict[key], key.ToVariableName())).ToArray();
56
37
 
57
38
  public static string[] FormatVariable(object val, string name)
@@ -65,11 +46,59 @@ public static string[] FormatVariable(object val, string name)
65
46
  case IDictionary<string, int> dict:
66
47
  return FormatMultiLineEnumerable(dict.Keys.Select((key, i) => $"[{Format(key)}] = {Format(dict[key])}" + (i < dict.Keys.Count - 1 ? "," : "")), name, "new Dictionary<string, int>");
67
48
  default:
68
- return new[] {$"var {name} = {Format(val)};"};
49
+ return new[] { $"var {name} = {Format(val)};" };
69
50
  }
70
51
  }
71
52
 
72
- private static string FormatString(this string s) => s.EscapeSpecialCharacters().Quote();
53
+ private static string Format(this string s) => s.EscapeSpecialCharacters().Quote();
54
+
55
+ private static string Format(this char c) => $"'{c}'";
56
+
57
+ private static string Format(this double dbl) => dbl.ToString(CultureInfo.InvariantCulture);
58
+
59
+ private static string Format(this float flt) => flt.ToString(CultureInfo.InvariantCulture);
60
+
61
+ private static string Format(this ulong ulng) => $"{ulng}UL";
62
+
63
+ private static string Format(this Enum @enumeration) =>
64
+ $"{enumeration.GetType().Name}.{enumeration}";
65
+
66
+ private static string Format(this Tuple<string, object> tuple) =>
67
+ $"Tuple.Create({tuple.Item1}, {tuple.Item2})";
68
+
69
+ private static string Format(this IEnumerable<int> ints) => ints.Any() ?
70
+ $"new[] {{ {string.Join(", ", ints)} }}" : "new int[0]";
71
+
72
+ private static string Format(this IEnumerable<string> strings) =>
73
+ strings.Any() ? $"new[] {{ {string.Join(", ", strings.Select(Format))} }}" : "new string[0]";
74
+
75
+ private static string Format(this IEnumerable<UnescapedValue> unescapedValues) =>
76
+ $"new[] {{ {string.Join(", ", unescapedValues.Select(Format))} }}";
77
+
78
+ private static string Format(this IDictionary<string, object> dict) =>
79
+ string.Join(", ", dict.Values.Select(Format));
80
+
81
+ private static string Format(this IDictionary<char, int> dict) =>
82
+ $"new Dictionary<char, int> {{ {string.Join(", ", dict.Keys.Select(key => $"[{Format(key)}] = {Format(dict[key])}"))} }}";
83
+
84
+ private static string Format(this IDictionary<string, int> dict) =>
85
+ $"new Dictionary<string, int> {{ {string.Join(", ", dict.Keys.Select(key => $"[{Format(key)}] = {Format(dict[key])}"))} }}";
86
+
87
+ private static string Format(this JArray jArray) =>
88
+ $"new[] {{ {string.Join(", ", jArray.Select(Format))} }}";
89
+
90
+ private static string Format(this int[,] multidimensionalArray)
91
+ {
92
+ return multidimensionalArray.GetLength(0) > 1
93
+ ? $"new[,]\r\n{{\r\n {string.Join(",\r\n ", Enumerable.Range(0, multidimensionalArray.GetUpperBound(0) + 1).Select(x => multidimensionalArray.SliceRow(x).ToNestedArray()))}\r\n}}"
94
+ : "new int[,] { }";
95
+ }
96
+
97
+ private static string Format(this IEnumerable<Tuple<string, object>> tuples) =>
98
+ $"new[] {{ {string.Join(", ", tuples.Select(Format))} }}";
99
+
100
+ private static string ToNestedArray<T>(this IEnumerable<T> enumerable) =>
101
+ enumerable.Any() ? $"{{ {string.Join(", ", enumerable)} }}" : string.Empty;
73
102
 
74
103
  private static string[] FormatMultiLineString(string name, string str)
75
104
  {
@@ -82,41 +111,13 @@ private static string[] FormatMultiLineString(string name, string str)
82
111
  return FormatMultiLineVariable(formattedStrings, name);
83
112
  }
84
113
 
85
- private static string[] FormatMultiLineEnumerable(IEnumerable<string> enumerable, string name, string constructor = null)
114
+ private static string[] FormatMultiLineEnumerable(IEnumerable<string> enumerable, string name, string constructor = null)
86
115
  => FormatMultiLineVariable(enumerable.Prepend("{").Append("}"), name, constructor);
87
116
 
88
- private static string[] FormatMultiLineVariable(IEnumerable<string> enumerable, string name, string constructor = null)
117
+ private static string[] FormatMultiLineVariable(IEnumerable<string> enumerable, string name, string constructor = null)
89
118
  => enumerable.Select(line => line == "{" || line == "}" ? line : line.Indent())
90
119
  .AddTrailingSemicolon()
91
120
  .Prepend($"var {name} = {constructor}")
92
121
  .ToArray();
93
-
94
- private static IEnumerable<string> AddTrailingSemicolon(this IEnumerable<string> enumerable)
95
- {
96
- var array = enumerable.ToArray();
97
- array[array.Length - 1] += ";";
98
- return array;
99
- }
100
-
101
- private static IEnumerable<T> SliceRow<T>(this T[,] array, int row)
102
- {
103
- for (var i = array.GetLowerBound(1); i <= array.GetUpperBound(1); i++)
104
- {
105
- yield return array[row, i];
106
- }
107
- }
108
-
109
- private static IEnumerable<T> SliceColumn<T>(this T[,] array, int column)
110
- {
111
- for (var i = array.GetLowerBound(0); i <= array.GetUpperBound(0); i++)
112
- {
113
- yield return array[i, column];
114
- }
115
- }
116
-
117
- private static string ToNestedArray<T>(this IEnumerable<T> enumerable)
118
- {
119
- return enumerable.Any() ? $"{{ {string.Join(", ", enumerable)} }}" : string.Empty;
120
- }
121
122
  }
122
123
  }
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "active": false,
3
- "exercises": [
4
- {
3
+ "exercises": [{
5
4
  "core": true,
6
5
  "difficulty": 1,
7
6
  "slug": "hello-world",
@@ -37,6 +36,19 @@
37
36
  "unlocked_by": "leap",
38
37
  "uuid": "c1cdab6f-c18c-4173-828a-2191151d20d4"
39
38
  },
39
+ {
40
+ "core": true,
41
+ "difficulty": 2,
42
+ "slug": "word-count",
43
+ "topics": [
44
+ "control_flow_loops",
45
+ "regular_expressions",
46
+ "maps",
47
+ "lists"
48
+ ],
49
+ "unlocked_by": "difference-of-squares",
50
+ "uuid": "b74dde02-03d0-4165-8302-e8ba119b486b"
51
+ },
40
52
  {
41
53
  "core": true,
42
54
  "difficulty": 2,
@@ -101,7 +113,7 @@
101
113
  "uuid": "99147c39-e8d3-4166-9215-c47fb4832781"
102
114
  },
103
115
  {
104
- "core": false,
116
+ "core": true,
105
117
  "difficulty": 1,
106
118
  "slug": "anagram",
107
119
  "topics": [
@@ -0,0 +1,18 @@
1
+ # Word Count
2
+
3
+ Given a phrase, count the occurrences of each word in that phrase.
4
+
5
+ For example for the input `"olly olly in come free"`
6
+
7
+ ```plain
8
+ olly: 2
9
+ in: 1
10
+ come: 1
11
+ free: 1
12
+ ```
13
+
14
+
15
+ For more detailed information about running tests, code style and linting, please see the [help page]("http://exercism.io/languages/dart").
16
+
17
+ ## Submitting Incomplete Solutions
18
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,26 @@
1
+ class WordCount {
2
+ Map<String, int> countWords(String input) {
3
+ Map<String, int> count = new Map();
4
+
5
+ /// make a list of all words using regex.
6
+ /// \\w+ matches any number of letters
7
+ /// e.g. one two three
8
+ /// \\w+'\\w => matches any number of letters then "'" and then a single letter
9
+ /// e.g. don't
10
+ /// \\d+ matches one or more digits
11
+ List<String> allWords = new List();
12
+ var wordMatches = new RegExp("\\w+'\\w|\\w+|d+").allMatches(input.toLowerCase());
13
+ for (var match in wordMatches) {
14
+ allWords.add(match.group(0));
15
+ }
16
+
17
+ /// Lists aka "arrays" have a forEach method that applies a function to
18
+ /// each element of the list.
19
+ /// initialize the Map with all words and there counter to 0
20
+ allWords.forEach((singleWord) => count[singleWord] = 0);
21
+
22
+ /// count all words and set there counter accordingly
23
+ allWords.forEach((singleWord) => count[singleWord] = count[singleWord] + 1);
24
+ return count;
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ class WordCount {
2
+ // Put your code here
3
+ }
@@ -0,0 +1,293 @@
1
+ # Generated by pub
2
+ # See http://pub.dartlang.org/doc/glossary.html#lockfile
3
+ packages:
4
+ analyzer:
5
+ description:
6
+ name: analyzer
7
+ url: "https://pub.dartlang.org"
8
+ source: hosted
9
+ version: "0.30.0+4"
10
+ args:
11
+ description:
12
+ name: args
13
+ url: "https://pub.dartlang.org"
14
+ source: hosted
15
+ version: "1.0.0"
16
+ async:
17
+ description:
18
+ name: async
19
+ url: "https://pub.dartlang.org"
20
+ source: hosted
21
+ version: "1.13.3"
22
+ barback:
23
+ description:
24
+ name: barback
25
+ url: "https://pub.dartlang.org"
26
+ source: hosted
27
+ version: "0.15.2+12"
28
+ boolean_selector:
29
+ description:
30
+ name: boolean_selector
31
+ url: "https://pub.dartlang.org"
32
+ source: hosted
33
+ version: "1.0.2"
34
+ charcode:
35
+ description:
36
+ name: charcode
37
+ url: "https://pub.dartlang.org"
38
+ source: hosted
39
+ version: "1.1.1"
40
+ cli_util:
41
+ description:
42
+ name: cli_util
43
+ url: "https://pub.dartlang.org"
44
+ source: hosted
45
+ version: "0.1.2+1"
46
+ collection:
47
+ description:
48
+ name: collection
49
+ url: "https://pub.dartlang.org"
50
+ source: hosted
51
+ version: "1.14.3"
52
+ convert:
53
+ description:
54
+ name: convert
55
+ url: "https://pub.dartlang.org"
56
+ source: hosted
57
+ version: "2.0.1"
58
+ crypto:
59
+ description:
60
+ name: crypto
61
+ url: "https://pub.dartlang.org"
62
+ source: hosted
63
+ version: "2.0.2+1"
64
+ csslib:
65
+ description:
66
+ name: csslib
67
+ url: "https://pub.dartlang.org"
68
+ source: hosted
69
+ version: "0.14.1"
70
+ front_end:
71
+ description:
72
+ name: front_end
73
+ url: "https://pub.dartlang.org"
74
+ source: hosted
75
+ version: "0.1.0-alpha.4.1"
76
+ glob:
77
+ description:
78
+ name: glob
79
+ url: "https://pub.dartlang.org"
80
+ source: hosted
81
+ version: "1.1.5"
82
+ html:
83
+ description:
84
+ name: html
85
+ url: "https://pub.dartlang.org"
86
+ source: hosted
87
+ version: "0.13.2"
88
+ http:
89
+ description:
90
+ name: http
91
+ url: "https://pub.dartlang.org"
92
+ source: hosted
93
+ version: "0.11.3+15"
94
+ http_multi_server:
95
+ description:
96
+ name: http_multi_server
97
+ url: "https://pub.dartlang.org"
98
+ source: hosted
99
+ version: "2.0.4"
100
+ http_parser:
101
+ description:
102
+ name: http_parser
103
+ url: "https://pub.dartlang.org"
104
+ source: hosted
105
+ version: "3.1.1"
106
+ isolate:
107
+ description:
108
+ name: isolate
109
+ url: "https://pub.dartlang.org"
110
+ source: hosted
111
+ version: "1.1.0"
112
+ js:
113
+ description:
114
+ name: js
115
+ url: "https://pub.dartlang.org"
116
+ source: hosted
117
+ version: "0.6.1"
118
+ kernel:
119
+ description:
120
+ name: kernel
121
+ url: "https://pub.dartlang.org"
122
+ source: hosted
123
+ version: "0.3.0-alpha.1.1"
124
+ logging:
125
+ description:
126
+ name: logging
127
+ url: "https://pub.dartlang.org"
128
+ source: hosted
129
+ version: "0.11.3+1"
130
+ matcher:
131
+ description:
132
+ name: matcher
133
+ url: "https://pub.dartlang.org"
134
+ source: hosted
135
+ version: "0.12.1+4"
136
+ meta:
137
+ description:
138
+ name: meta
139
+ url: "https://pub.dartlang.org"
140
+ source: hosted
141
+ version: "1.1.2"
142
+ mime:
143
+ description:
144
+ name: mime
145
+ url: "https://pub.dartlang.org"
146
+ source: hosted
147
+ version: "0.9.3"
148
+ node_preamble:
149
+ description:
150
+ name: node_preamble
151
+ url: "https://pub.dartlang.org"
152
+ source: hosted
153
+ version: "1.4.0"
154
+ package_config:
155
+ description:
156
+ name: package_config
157
+ url: "https://pub.dartlang.org"
158
+ source: hosted
159
+ version: "1.0.3"
160
+ package_resolver:
161
+ description:
162
+ name: package_resolver
163
+ url: "https://pub.dartlang.org"
164
+ source: hosted
165
+ version: "1.0.2"
166
+ path:
167
+ description:
168
+ name: path
169
+ url: "https://pub.dartlang.org"
170
+ source: hosted
171
+ version: "1.4.2"
172
+ plugin:
173
+ description:
174
+ name: plugin
175
+ url: "https://pub.dartlang.org"
176
+ source: hosted
177
+ version: "0.2.0+2"
178
+ pool:
179
+ description:
180
+ name: pool
181
+ url: "https://pub.dartlang.org"
182
+ source: hosted
183
+ version: "1.3.3"
184
+ pub_semver:
185
+ description:
186
+ name: pub_semver
187
+ url: "https://pub.dartlang.org"
188
+ source: hosted
189
+ version: "1.3.2"
190
+ shelf:
191
+ description:
192
+ name: shelf
193
+ url: "https://pub.dartlang.org"
194
+ source: hosted
195
+ version: "0.7.0"
196
+ shelf_packages_handler:
197
+ description:
198
+ name: shelf_packages_handler
199
+ url: "https://pub.dartlang.org"
200
+ source: hosted
201
+ version: "1.0.3"
202
+ shelf_static:
203
+ description:
204
+ name: shelf_static
205
+ url: "https://pub.dartlang.org"
206
+ source: hosted
207
+ version: "0.2.5"
208
+ shelf_web_socket:
209
+ description:
210
+ name: shelf_web_socket
211
+ url: "https://pub.dartlang.org"
212
+ source: hosted
213
+ version: "0.2.2"
214
+ source_map_stack_trace:
215
+ description:
216
+ name: source_map_stack_trace
217
+ url: "https://pub.dartlang.org"
218
+ source: hosted
219
+ version: "1.1.4"
220
+ source_maps:
221
+ description:
222
+ name: source_maps
223
+ url: "https://pub.dartlang.org"
224
+ source: hosted
225
+ version: "0.10.4"
226
+ source_span:
227
+ description:
228
+ name: source_span
229
+ url: "https://pub.dartlang.org"
230
+ source: hosted
231
+ version: "1.4.0"
232
+ stack_trace:
233
+ description:
234
+ name: stack_trace
235
+ url: "https://pub.dartlang.org"
236
+ source: hosted
237
+ version: "1.8.2"
238
+ stream_channel:
239
+ description:
240
+ name: stream_channel
241
+ url: "https://pub.dartlang.org"
242
+ source: hosted
243
+ version: "1.6.2"
244
+ string_scanner:
245
+ description:
246
+ name: string_scanner
247
+ url: "https://pub.dartlang.org"
248
+ source: hosted
249
+ version: "1.0.2"
250
+ term_glyph:
251
+ description:
252
+ name: term_glyph
253
+ url: "https://pub.dartlang.org"
254
+ source: hosted
255
+ version: "1.0.0"
256
+ test:
257
+ description:
258
+ name: test
259
+ url: "https://pub.dartlang.org"
260
+ source: hosted
261
+ version: "0.12.24+8"
262
+ typed_data:
263
+ description:
264
+ name: typed_data
265
+ url: "https://pub.dartlang.org"
266
+ source: hosted
267
+ version: "1.1.5"
268
+ utf:
269
+ description:
270
+ name: utf
271
+ url: "https://pub.dartlang.org"
272
+ source: hosted
273
+ version: "0.9.0+3"
274
+ watcher:
275
+ description:
276
+ name: watcher
277
+ url: "https://pub.dartlang.org"
278
+ source: hosted
279
+ version: "0.9.7+4"
280
+ web_socket_channel:
281
+ description:
282
+ name: web_socket_channel
283
+ url: "https://pub.dartlang.org"
284
+ source: hosted
285
+ version: "1.0.6"
286
+ yaml:
287
+ description:
288
+ name: yaml
289
+ url: "https://pub.dartlang.org"
290
+ source: hosted
291
+ version: "2.1.13"
292
+ sdks:
293
+ dart: ">=1.23.0 <2.0.0-dev.infinity"