Skip to content

heathdbrown/never_nesting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Never Nesting

From https://www.youtube.com/watch?v=CFRhGnuXG-4

Original

int calculate(int bottom, int top)
{
    if (top > bottom)
    {
        int sum = 0;

        for (int number = bottom; number <= top; number ++>)
        {
            if (number % 2 == 0)
            {
                sum += number;
            }
        }
        return sum;
    }
    else
    {
        return 0;
    }
}

Extraction

  • pull out parts that can to functions

invert

  • move the negative results out of 'else' conditions

Releases

No releases published

Packages

No packages published

Languages