Edabit

Create a function that returns the sum of missing numbers.

Examples

 sumMissingNumbers([1, 3, 5, 7, 10]) ➞ 29 // 2 + 4 + 6 + 8 + 9  sumMissingNumbers([10, 7, 5, 3, 1]) ➞ 29  sumMissingNumbers([10, 20, 30, 40, 50, 60]) ➞ 1575 

Notes

The minimum and maximum value of the given array are the inclusive bounds of the numeric range to consider when searching for missing numbers.

Solution:

function sumMissingNumbers(arr) { 	let min = Math.min(...arr); 	let max = Math.max(...arr); 	let sum = 0; 	for(let i = min;i<max; i++){ 		if(!arr.includes(i)){ 			sum+=i; 		} 	} 	return sum; } 

This free site is ad-supported. Learn more