Pergunta de entrevista da empresa Algotec

Write a function that gets an array of numbers and zero's and returns the array without the zero values. should be consider run time (without extra memory)

Resposta da entrevista

Sigiloso

7 de jul. de 2016

var array = [0,1,0,1,2,0,4,0,6,0]; function pushZeroToEnd(array){ var count = 0; //for each number, put it at the begining of the array, keeping the order of the numbers for (var i = 0; i < array.length; i++){ if(array[i] !== 0){ array[count++] = array[i]; } } //count is the last real number, so from here splice the array return array(count, array.length-1); } pushZeroToEnd(array);