I am making a function that returns an arbitrary term of a linear sequence. The test cases look like this:
Test.assertEquals(getFunction([0, 1, 2, 3, 4])(5), 5, "Nope! Try again.");
Test.assertEquals(getFunction([0, 3, 6, 9, 12])(10), 30, "Nope! Try again.");
Test.assertEquals(getFunction([1, 4, 7, 10, 13])(20), 61, "Nope! Try again.");
I don't understand the function invocation. I have written this code to determine the function of the linear sequence and compute an arbitrary term, but I don't know how to pass my function the term to compute:
function getFunction(sequence) {
var diff = sequence[1] - sequence[0];
var init = sequence[0];
return diff*arguments[1]+init;
}
arguments[1] doesn't access the term passed in after the parameters. How can I access the term (5) in the first example?
Test.assertEquals(getFunction([0, 1, 2, 3, 4])(5), 5, "Nope! Try again.");
getFunction([...])returns a function which takes 5 in argument (for the first test case), you won't reach the argument5fromgetFunction