interfaceIndexValue{index:number;value:number;}/**
* Return all numbers with their index & value that are not following the others.
*
* @example
* getNonConsecutives([1, 2, 3]);
* getNonConsecutives([1, 2, 4]);
*/functiongetNonConsecutives(numbers:Readonly<Array<number>>):Array<IndexValue>{constnonConsecutives:Array<IndexValue>=[];constcount:number=numbers.length;for(letindex:number=1;index<count;index++){constcurrent:number=numbers[index];constprevious:number=numbers[index-1];constexpectedCurrent:number=previous+1;if(expectedCurrent===current){continue;}nonConsecutives.push({index,value:current});}returnnonConsecutives;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TypeScript