its not returning anything, but return true or false are getting executed fine. Whenever array contains all odd number it should reach return true as array will be empty and return false if array element is not a odd number.
function isOdd(a) {
return a % 2 == 1 ? true : false
}
function someRecursive(ary, isOdd) {
if(ary.length == 0){
return true;
}
if(isOdd(ary[0])){
someRecursive(ary.slice(1), isOdd);
}else{
return false;
}
}
someRecursive([1,3, 5], isOdd);
You are not returning anything inside if condition. Return the value returned by the recursive function.
Some thing like this :
if(isOdd(ary[0])){
return someRecursive(ary.slice(1), isOdd);
}
function isOdd(a) {
return a % 2 == 1 ? true : false
}
function someRecursive(ary, isOdd) {
if(ary.length == 0){
return true;
}
if(isOdd(ary[0])){
return someRecursive(ary.slice(1), isOdd);
}else{
return false;
}
}
console.log(someRecursive([1,3, 5], isOdd))