i have an array of mixed numbers, from that i need to shift the zero numbered to end without changing the nonzero numbers order in plain JAVASCRIPT.
Note: this need to be handled without creating a new array.
Ex:
inp_arr = [12,5,0,78,94,0,34,0,67];
expected output:
[12,5,78,94,34,67,0,0,0];
the way i implemented :
function sortArray(inputArray){
let non_zeroArray = []
let zero_Array = [];
inputArray.map(item => {
item != 0 ? non_zeroArray.push(item) : zero_Array.push(item)
});
return non_zeroArray.concat(zero_Array)
}
console.log(
sortArray([32, 0, 12, 78, 0, 56, 0, 87, 0])
)