helper method recursion

gongyoon·2022년 7월 11일
0

Helper Method Recursion

재귀함수에서 중요한점은 죵료 시점을 넣어야 한다는 것.
동작은 Call Stack으로 이루어진다.

다음 방식으로 입력한 배열 중 홀수를 골라내는 재귀함수를 만들어 보았다.

function helperMethodRecursion(helperInput){
	const result = [];

    function recursion(helperInput){
    	if(helperInput.length === 0) return;
  
        if(helperInput[0] % 2 !== 0){
        	result.push(helperInput[0]);
        }
 
        helper(helperInput.slice(1));

	helper(helperInput);

    return result;
}
profile
공부하며 성장하는 사람이 되고 싶은 개발자.

0개의 댓글