38.Moving Zeros To The End
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0] function moveZeros(arr) { let array = arr.filter((num) => num !== 0); for (i=0; i < arr.length; i++) { if (arr[i] === 0) { array.push(0) } } return array; } 우선 주어진 숫자로 되어있는 배열에서 0을 제거해주었다. filter() let a..
2022. 4. 14.