EcmaScript 6 Map
function uniquesOnly ( source ) {
var uniqueness = new Map();
source.forEach( function ( value ) {
switch ( uniqueness.get( value )) {
case undefined: uniqueness.set( value, true ); return;
case true: uniqueness.set( value, false );
}
});
return source.filter( function ( value ) {
return uniqueness.get( value );
});
}
alert(uniquesOnly([1, 2, 1, 10, 5, 3, 4, 40, 50]));