Skip to content

Instantly share code, notes, and snippets.

View pedropmota's full-sized avatar

Pedro Paulo Mota pedropmota

  • Denver, CO
View GitHub Profile
@pedropmota
pedropmota / CollectionExtensions.cs
Created March 7, 2018 21:37
C# method for getting all possible combinations of elements
/// <summary>
/// Gets all possible combinations of the specified list, based on the specified length of each resulting element.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="length"></param>
/// <param name="check">Additional check before adding an element to the final result. (t1 = IEnumerable of T, t2 = T)</param>
/// <returns></returns>
static IEnumerable<IEnumerable<T>> GetCombinations<T>(IEnumerable<T> list, int length,
Func<IEnumerable<T>, T, bool> check = null)
@pedropmota
pedropmota / pokerDeckOfCards.js
Last active August 4, 2018 17:10
An example of a deck of poker cards. Contains the Enum and Class definitions. At the end, there's an example of how to use the deck.
/**
* Helper function that creates an object based on an array of values,
* setting each key/value with an item from the array.
* @param {Array} array The array of values
*/
function createEnum(array) {
return array.reduce((object, value) => {
object[value] = value;
return object;