## The challenge

An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of numbers that have been given to you. The rest of the given series is the same as the original AP. Find the missing term.

You have to write a function that receives a list, list size will always be at least 3 numbers. The missing term will never be the first or last one.

Example:

 ``````1 `````` ``````findMissing([1, 3, 5, 9, 11]) == 7 ``````

## The solution in Javascript

Option 1:

 ``````1 2 3 `````` ``````var findMissing = function (l) { return ((l+l[l.length-1])*(l.length+1))/2-(l.reduce((a,b)=>a+b)) } ``````

Option 2:

 ``````1 2 3 4 `````` ``````var findMissing = function (list) { let delta = (list[list.length - 1] - list)/list.length; return list.find( (el,ind) => el !== ind*delta + list) - delta; } ``````

Option 3:

 `````` 1 2 3 4 5 6 7 8 9 10 11 `````` ``````var findMissing = function (list) { var listLen = list.length; var iter = (list[listLen-1]-list)/listLen; for(i = 0; i < listLen; i++){ var next = list[i] + iter if(next != list[i+1]){ return next; } } } ``````

## Test cases to validate our solution

 ``````1 2 3 4 5 6 7 8 `````` ``````for (let i = 0;i < 10;++i) { fixture.random (1+i*5,0) ; fixture.random (1+i*5,10) ; fixture.random (1+i*5,100) ; fixture.random (1+i*5,1000) ; fixture.random (1+i*5,10000) ; fixture.random (1+i*5,100000) ; } ``````