Code in harness
You,•dart + flutter
When you do competitive tests, it is good to make sure that your code goes inside a strict route, by putting it in a harness building a small harness is just a couple of extra functions etc; here is an example of a example
- one function returns input
- one function processes input and returns output
- main function uses above two
- takes input
- processes it and gets output
- prints output
using this style is good for testing. happy coding !
//harness
List<double> getInput()
{
return [1,2,6,341,5,6];
}
//find average without dynamic fat arrow functions
double findAverage(List inputValues)
{
double sum = 0.0;
for(int i = 0; i<inputValues.length;i++)
{
sum += inputValues[i];
}
if(inputValues.isEmpty) return 0;
return (sum/inputValues.length);
}
void main()
{
List vals = getInput();
double av = findAverage(vals);
print("The average is $av");
}
Output:
The average is 60.166666666666664