JSFiddle - React, Tailwind, and code Playground

by e_kurbanov

JavaScript

function solution(A) {
    A.sort(function(a,b){return a - b});
    for(var i = 0; i < A.length; i++){	
    		if(A[i + 1] - A[i] !== 1){
       			 console.log( A[i] + 1 ) ;
        }
        else{
        		console.log( A[i]  )
        }
      	
    }
}

solution([2, 3, 1, 5]);