The Missing Link of an Arithmetic Progression

Published by Matt in

Your function will get an array with a number sequence. However, one item will be missing. It's your job to find out which one is not in the array.

To illustrate, given the array [1, 3, 4, 5], 2 is missing so the output must be 2.

Examples

missing([1, 3, 4, 5]) ➞ 2

missing([2, 4, 6, 8, 10, 14, 16]) ➞ 12

missing([1.5, 2, 3]) ➞ 2.5

Notes

  • The missing item will never be the smallest or largest number in the array.
  • In every array, exactly one item is missing.
Watch a quick demo on how Edabit works.