I have this code in JS
function calc(bth){
var y,cont;
y=(Math.abs(1965-bth))/4;
y=y-Math.floor(y);
if(y){
cont=calc(bth+1);
return(cont+1);
} else {
return(1); // <-- what is the meaning of this line?
}
}
I converted it to PHP as
function calc($yr)
{
$y = (abs(1965 - $yr))/4;
$y = $y- floor($y);
if($y)
{
$cont= calc($yr+1);
return ($cont + 1);
}
else
{
return (1); //<--- stuck here
}
}
I realized that return (1)
in javascript is not the same as return (1)
in PHP. I went over some SO topics regarding this topic but didn't find a suitable match for my kind of scenario.
In my context, what would return (1)
return in javascript? I would also appreciate if the values of return (0)
and return (-1)
in javascript are made known to me so that I get acquainted with this information.
Don't overcomplicate the problem. It will simply return 1
, as if you write return 1
.
Most probably brackets were left from copying of return(cont+1)
.
return
is not a function, ()
is not necessary for return statement.
Just do with return cont + 1;
and return 1;