Skip to main content
edited body
Source Link

Arguably a better variant for DeflateArray:

private decimal[] DeflateArray(decimal[] items, decimal deflateRate)
{
    return items
        .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
        .ToArray();
}

It's better in a way it helps avoiding OBOE.

And by the way, another thing you can do is define it as an extension method in a separate static class, and will be able to invoke it as myArrayOfDecimals.DeflateArrayWithRate(1.5d5m):

public static class DecimalArrayExtensions
{
    public static decimal[] DeflateArrayWithRate(this decimal[] items, decimal deflateRate)
    {
        return items
            .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
            .ToArray();
    }

    private static decimal PowerOf(decimal x, decimal y)
    {
        return (decimal)Math.Pow((double)x, (double)y);
    }
}

Arguably a better variant for DeflateArray:

private decimal[] DeflateArray(decimal[] items, decimal deflateRate)
{
    return items
        .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
        .ToArray();
}

It's better in a way it helps avoiding OBOE.

And by the way, another thing you can do is define it as an extension method in a separate static class, and will be able to invoke it as myArrayOfDecimals.DeflateArrayWithRate(1.5d):

public static class DecimalArrayExtensions
{
    public static decimal[] DeflateArrayWithRate(this decimal[] items, decimal deflateRate)
    {
        return items
            .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
            .ToArray();
    }

    private static decimal PowerOf(decimal x, decimal y)
    {
        return (decimal)Math.Pow((double)x, (double)y);
    }
}

Arguably a better variant for DeflateArray:

private decimal[] DeflateArray(decimal[] items, decimal deflateRate)
{
    return items
        .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
        .ToArray();
}

It's better in a way it helps avoiding OBOE.

And by the way, another thing you can do is define it as an extension method in a separate static class, and will be able to invoke it as myArrayOfDecimals.DeflateArrayWithRate(1.5m):

public static class DecimalArrayExtensions
{
    public static decimal[] DeflateArrayWithRate(this decimal[] items, decimal deflateRate)
    {
        return items
            .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
            .ToArray();
    }

    private static decimal PowerOf(decimal x, decimal y)
    {
        return (decimal)Math.Pow((double)x, (double)y);
    }
}
Source Link

Arguably a better variant for DeflateArray:

private decimal[] DeflateArray(decimal[] items, decimal deflateRate)
{
    return items
        .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
        .ToArray();
}

It's better in a way it helps avoiding OBOE.

And by the way, another thing you can do is define it as an extension method in a separate static class, and will be able to invoke it as myArrayOfDecimals.DeflateArrayWithRate(1.5d):

public static class DecimalArrayExtensions
{
    public static decimal[] DeflateArrayWithRate(this decimal[] items, decimal deflateRate)
    {
        return items
            .Select((item, index) => item /= PowerOf(1 + deflateRate, index))
            .ToArray();
    }

    private static decimal PowerOf(decimal x, decimal y)
    {
        return (decimal)Math.Pow((double)x, (double)y);
    }
}