This file contains hidden or 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
| function Add(values) { | |
| return values.reduce((sum, val) => sum += val) | |
| } |
This file contains hidden or 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
| function Add(values) { | |
| let sum = 0 | |
| values.forEach(val => sum += val) | |
| return sum | |
| } |
This file contains hidden or 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
| function Add(values) { | |
| let sum = 0 | |
| for (var value of values) { | |
| sum += value | |
| } | |
| return sum | |
| } |
This file contains hidden or 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
| function Add(values) { | |
| let sum = 0 | |
| const length = values.length | |
| for (var i = 0; i < length; i++) { | |
| sum += values[i] | |
| } | |
| return sum | |
| } |
This file contains hidden or 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
| static void Main() { | |
| foreach (var line in TellJokeAboutMice()) | |
| { | |
| Console.WriteLine(line); | |
| } | |
| } | |
| private static IEnumerable<string> TellJokeAboutMice() | |
| { | |
| yield return "MR MICE."; |
This file contains hidden or 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
| internal class EnumeratorAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| IEnumerator<int> enumerator = values.AsEnumerable().GetEnumerator(); | |
| int sum = 0; | |
| while (enumerator.MoveNext()) | |
| { | |
| sum += enumerator.Current; | |
| } |
This file contains hidden or 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
| internal class ForEachLoopAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| int sum = 0; | |
| foreach (var value in values) | |
| { | |
| sum += value; | |
| } | |
| return sum; |
This file contains hidden or 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
| internal unsafe class ArrayPointerAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| int sum = 0; | |
| int count = values.Length; | |
| fixed (int *p = values) | |
| { | |
| for (int i = 0; i < count; i++) | |
| { |
This file contains hidden or 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
| internal class GotoAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| int sum = 0; | |
| int count = values.Length; | |
| int index = 0; | |
| BEGIN: | |
| if (index == count) goto RETURN; | |
| int value = values[index++]; |
This file contains hidden or 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
| internal class ForLoopAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| int sum = 0; | |
| int count = values.Length; | |
| for (int i = 0; i < count; i++) | |
| { | |
| int value = values[i]; | |
| sum += value; |