start
과 history
는 어떻게 가치를 얻습니까?. 어디에서 왔습니까?. 이 링크를 읽고 있습니다.
아는 사람이 있으면 설명해주세요.
산출
(((1 * 3) + 5) * 3)
function findSolution(target) {
function find(start, history) {
if (start == target)
return history;
else if (start > target)
return null;
else
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
}
return find(1, "1");
}
console.log(findSolution(24));
function findSolution(target) {
function find(start, history) { // <--- NOTICE DECLARATIONS HERE
/* SNIP */
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
} // ^--- FUNCTION CALLS HERE
return find(1, "1"); // <--- AND HERE
}
console.log(findSolution(24));
이 질문과 관련이없는 세부 사항을 찾아 내고 몇 가지 의견을 삽입했습니다. 보시다시피, 함수 find
는 문제의 두 인수 start
와 history
. find
처음으로 호출 1
에 대한 값 start
과 "1"
값으로서 history
. 그 다음에 find
함수는 이러한 인수에 대한 새 값으로 자신을 재귀 적으로 호출합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다