Skip to content

Extension idea #31

@iamprovidence

Description

@iamprovidence
  • ArrayShift
  • Map
public static decimal Map (this decimal value, decimal fromSource, decimal toSource, decimal fromTarget, decimal toTarget)
{
        return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}
  • Lerp Color
Color lerp(Color a, Color b, float t)
{
    t = clamp01(t);
    return new Color(
        a.r + (b.r - a.r) * t,
        a.g + (b.g - a.g) * t,
        a.b + (b.b - a.b) * t,
        a.a + (b.a - a.a) * t
    );
}
  • constrain value (with min, max)
  • SubArray
public static T[] SubArray<T>(this T[] data, int index, int length)
{
    T[] result = new T[length];
    Array.Copy(data, index, result, 0, length);
    return result;
}
static void Main()
{
    int[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    int[] sub = data.SubArray(3, 4); // contains {3,4,5,6}
}
  • Skip take => offset
array.Skip(3).Take(5).ToArray();
  • permutation (all, Next, Prev)
public static IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> list, int length)
            {
                if (length == 1) return list.Select(t => new T[] { t });

                return GetPermutations(list, length - 1)
                    .SelectMany(t => list.Where(e => !t.Contains(e)),
                        (t1, t2) => t1.Concat(new T[] { t2 }));
            }
  • Factorial
int Factorial(int i)
{
    if (i <= 1)
        return 1;
    return i * Factorial(i - 1);
}
  • Enumerable.Range with step, similar to python one
  • string.Rerlace (stringBuilder)
    two char arrays, go through cycle, change one letter from first array to another. maybe use Dictionary

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions