0

Firstly, we need a general function that can be used to sum the numbers between two integers. This means that the function should take two integers as parameters. Something similar to this:

svg viewer

Next, the function should be able to sum the integers in any form. In other words, we should be able to specify to the function that ‘compute the sum of the squares of the given integers’ or ‘compute the sum of the halves of the given integers.’ Any operation can be applied to the integers. This means that along with the list of parameters for the two integers, our function should also take another function as a parameter, a helper function, that would be applied on the integer parameters. Something similar to this:

svg viewer

Finally, the helper function should be such that it takes one integer, performs some operation on the integer and returns the modified integer as a result.

svg viewer

Implementation

By breaking down the problem, we were able to figure out that our sum function should have two parameter lists. The first list will contain a single argument and the second list will contain two arguments.

Source: Grepper

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.

Grepper Account Login Required