← Back to challenges

Sum of Missing Numbers

JavaScriptHardmathnumbersvalidation

Instructions

Create a function that takes an array of "mostly" numbers and returns the total amount of missing numbers, given that the array is sorted in ascending order. Watch out for strings!

Examples

sumOfMissingNums(["1", "3", "5", "7", "9"]) ➞ 4
// 1+1+1+1

sumOfMissingNums(["7", "3", "1", "9", "5"]) ➞ 4

sumOfMissingNums(["1", "5", "B", "9", "z"]) ➞ 6

Notes

The data might be dirty! Clean out any filthy strings.

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