var answer = function(A,B,C,D){ var arr = [A,B,C,D]; arr.sort(); var numA = arr[0]; var numB = arr[1]; var numC = arr[2]; var numD = arr[3]; if(numD - numC == 1 && numC - numB == 1 && numB - numA == 1){ console.log('Yes'); } else { console.log('No'); } } answer(5,7,3,9);