JSFiddle - React, Tailwind, and code Playground
JavaScript
var ar = [ 21, 19, 18, 15, 13, 17 ]
ar.sort((a, b)=> a-b)//13, 15, 17, 18, 19, 21
console.log(`Sorted Array ${ar}`)
ar.forEach((val, index)=> {
console.log(index, 'val');
if ((ar[index+1])-(ar[index]) === 1) {
console.log(val+1);
//return;
}
})