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 IEnumerable<string> GetPermutations(string s) | |
{ | |
if (s.Count() > 1) | |
return from ch in s | |
from permutation in GetPermutations(s.Remove(s.IndexOf(ch), 1)) | |
select string.Format("{0}{1}", ch, permutation); | |
else | |
return new string[] { s }; | |
} |
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 List<string> Permutations(string s) | |
{ | |
if (s.Length == 1) | |
{ | |
return new List<string> { s }; | |
} | |
List<string> permutations = new List<string>(); | |
foreach (char c in s) |
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 void FizzBuzz() | |
{ | |
Dictionary<Func<int, bool>, Func<int, string>> rules = new Dictionary<Func<int, bool>, Func<int, string>>(); | |
rules.Add(x => x % 3 == 0, x => "fizz"); | |
rules.Add(x => x % 5 == 0, x => "buzz"); | |
rules.Add(x => x % 5 != 0 && x % 3 != 0, x => x.ToString()); | |
rules.Add(x => true, x => "\n"); | |
var output = from n in Enumerable.Range(1, 100) | |
from f in rules |
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
ar salesMan = GetSalesMan(); | |
var noOfOrders = GetSalesManNoOfOrders(salesMan); | |
var customers = GetSalesManCustomers(salesMan); | |
var provision = GetSalesManProvision(salesMan); | |
// etc. |
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
// In fighting code | |
switch(classType) | |
{ | |
case WARRIOR: | |
swingSword(); | |
break; | |
case MAGE: | |
castSpell(); | |
break; | |
case THIEF: |
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
String newWord ="" | |
for(int index = oldWord.Length – 1; index <= 0; index—) | |
newWord += oldWord[index]; | |
return newWord; |
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
var a = “first variable”; | |
function myfunction () { | |
var b = “ second variable”; | |
console.log(b); | |
} | |
console.log(a) // => ‘first variable’ | |
myfunction(); //=> ‘second variable’ |
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
private apocalypseStateMachine = new ApocalypseStateMachine(); | |
public ApocalypseScenario CreateNew() | |
{ | |
if(apocalypseStateMachine.State == States.PENGUIN_SLAUGHTER) | |
return new ApocalypseScenario("Penguin Apocalypse, Code Blue"); | |
} |
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 interface ILostOrderService | |
{ | |
IEnumerable<Orders> GetLostOrders(int customerId); | |
IEnumerable<Customer> GetCustomerWithLostOrders() | |
} | |
public class LostOrderServiceWrapper : ILostOrderService | |
{ | |
public IEnumerable<Orders> GetLostOrders(int customerId) | |
{ |
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 void LoginAsCustomer(LoginInfo loginInfo, CustomerType customerType = CustomerType.NEW_CUSTOMER, int numberOfTries = 3) | |
{ | |
// ... | |
} | |
var loginInfo = new LoginInfo("Darth Vader", "ihatewookes"); | |
LoginAsCustomer(loginInfo); | |
// What if we need to override a default? No problem. |
NewerOlder