0
이상한 자바 스크립트 기능 프로그래밍 구멍에 붙어 있습니다. 여기재귀 검색 함수에서 두 개의 값을 반환 할 수 있습니까?
그것입니다
// Given an integer n, can n be reached by some combination of plus five and times three?
function recursiveSearch (n) {
// if attempt matches return success
// if attempt produces neutral keep trying
// if attempt matches less than 1 return failure
if (n === 1) return true
if (n > 1) {
return recursiveSearch(n-5), recursiveSearch(n/3)
}
else return false
}
console.log(1, recursiveSearch(1))
console.log(3, recursiveSearch(3))
console.log(6, recursiveSearch(6))
console.log(7, recursiveSearch(7))
console.log(9, recursiveSearch(9))
console.log(13, recursiveSearch(13))
console.log(51, recursiveSearch(51))
console.log(247, recursiveSearch(247))
내가 분명히 함수에서 다른 두 가지를 반환 할 수는 없지만, 내가 돌아 오지 않으면 내 검색에서 분기 할 수 없습니다
if (n > 1) {
recursiveSearch(n-5)
recursiveSearch(n/3)
}
그냥 정의되지 않은 값을 생성합니다.
가능한 복제 [반품 자바 스크립트에서 여러 값?] (http://stackoverflow.com/questions/2917175/return-multiple-values-in-javascript) – dorukayhan