Moving Zero To The End

samuel Jo·2022년 11월 28일
0

codewars

목록 보기
7/46
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]

arr의 배열에 0이있다면 0을 맨뒤로 보내주는 문제다.

처음에 sort([비교값])오름차순 뒤 reverse()메서드를 사용하고 테스트를 했는데 에러가 떠서 문제를 다시봄. 0인것만 뒤로 움직이고 나머지는 그대로인 내용을 보고 코드를 다시작성.

profile
step by step

0개의 댓글