Created
May 3, 2018 20:49
-
-
Save fredyfx/0309bcb057662aaa7fc9cb10b18bf1a4 to your computer and use it in GitHub Desktop.
Jugando con los Generics
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
// Note that you can return any data structure you want, as long it inherits the IEnumerable interface. | |
UniqueInOrder("AAAABBBCCDAABBB") => "ABCDAB" | |
UniqueInOrder("ABBCcAD") => "ABCcAD" | |
UniqueInOrder("12233") => "123" | |
UniqueInOrder(new List<double> {1.1, 2.2, 2.2, 3.3}) => new List<double> {1.1, 2.2, 3.3} |
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
using System.Collections.Generic; | |
public static class Kata | |
{ | |
public static IEnumerable<T> UniqueInOrder<T>(IEnumerable<T> iterable) | |
{ | |
List<T> result = new List<T>(); | |
T pre_item = default(T); | |
foreach (T item in iterable) { | |
if(!item.Equals(pre_item)){ | |
result.Add(item); | |
pre_item = item; | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment