Hi I started with JS and wanted to get missing element from an array. In case there is no element missing I want to get null. However I can either get null or the element I want. Both not working at the same time. Could you help ? Thank you in advance
function getMissingElement(array) {
for (var i = 0; i < array.length; i++) {
if (Math.abs(array[i + 1] - array[i] != 1)) {
return (array[i + 1] - 1);
} else {
return null
}
}
}
getMissingElement([1, 2, 3, 4, 5, 6, 7]);
getMissingElement([6, 7, 8, 10, 11, 12, 13, 14, 15])