var inputs = [4, 2, 5, 2, 3, 4, 4, 5, 6, 7, 1, 3, 6, 8];
var duplicates = [];
var result = 0;
for (var i = 0; i < inputs.length; i++) {
for (var c = 0; c < inputs.length; c++) {
if (inputs[i] == inputs[c]) {
result = result + 1;
if (result == 2) {
if (duplicates.indexOf(inputs[c]) !== -1) {
} else {
duplicates.push(inputs[c]);
}
}
}
}
result = 0;
}
console.log(duplicates.sort());