jQuery addClass example
Change class name on click in jQuery
HTML
<pre id='pre'></pre>
JavaScript
const $pre = $('#pre');
const data = [1, 4, 9, 78, 42, 4, 11, 56];
let duplIndex;
const res = data.map((el, index) => {
duplIndex = data.indexOf(el, index+1);
if(duplIndex !== -1){
return {el:el, gap: duplIndex - (index + 1)}
}
}).filter((el) => {
return el !== undefined;
})
$pre.text(JSON.stringify(res));