← Back to challenges

Next Element in Arithmetic Sequence

JavaScriptHardarraysnumbersmath

Instructions

Create a function that returns the next element in an arithmetic sequence. In an arithmetic sequence, each element is formed by adding the same constant to the previous element.

Examples

nextElement([3, 5, 7, 9]) ➞ 11

nextElement([-5, -6, -7]) ➞ -8

nextElement([2, 2, 2, 2, 2]) ➞ 2

Notes

All input arrays will contain integers only.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Capture the Rook