Ваяс,
var array = [1, 2, 1, 10, 5, 3, 4, 40, 50],
i = array.length,
result = [];
array.sort(function (a, b) {
return a - b;
});
for (var i = 0; i < array.length; i++) {
array[i] != array[i - 1] && array[i + 1] != array[i] && result.push(array[i])
}
alert(result);