This is how I would see it:
In= [-1,150,190,170,-1,-1,160,180];
Filtered= [150,190,170,160,180];
Sorted= [150,160,170,180,190];
Out= [-1,150,160,170,-1,-1,180,190];
[Update]
Good start, now you need to build out array with respect to positions of -1 in original
function solution(x){
var arr = [];
for(var i = 0; i < x.length; i++){
if(x[i] != -1){
arr.push(x[i]);
}
}
arr = arr.sort(function(a,b){return a-b});
return arr;
}
console.log(solution([-1,150,190,170,-1,-1,180,160]));