JSFiddle - React, Tailwind, and code Playground
by saidulu401
JavaScript
//Find the missing number in an array of consecutive integers.
const detectiveArray = [1, 2, 3,4, 5, 6,8];
function findMissingNumber(arr){
const max = Math.max(...arr)
const expectedTotal = (max+1)*(max)/2
const actualTotal = arr.reduce((a,b)=>a+b,0);
return expectedTotal - actualTotal;
}
console.log(findMissingNumber(detectiveArray))