javascript - Converting a simple function from jS to PHP -
i have simple function hash function in js i'm struggeling converting php (for server side validation), simple math function, , i'm not php expert, of shed light why can't have ($variable)(function) in php next each other?
here function in js:
function claculate(a,b){ var g=function(a){ return math.round(a/math.pow(10,math.round(math.log10e*math.log(a)))*10) }; var f=function(a){ var h=function(b){ return b(a) }; var j=function(b){ return g(a) }; return a<b?j:h }; var o=((f(a)(g)%2)||(f(a*b)(g)%7*1/7)||11)^f(b)(g); return another_function(a,o); }
and here version in php, there error on $o line, , i'm not sure why ...
function claculate($a, $b){ $g = function ($r){ return round($r / pow(10, round(m_log10e * log($r))) * 10); }; $f = function ($a) use (&$a, &$b, &$g) { $h = function ($b) use (&$b, &$a) { return $b($a); }; $j = function ($b) use (&$b, &$g, &$a) { return $g($a); }; return ($a < $b) ? $j : $h; }; // $o throws error $o = $f($a)($g) % 2 || $f($a * $b)($g) % 7 * 1 / 7 || 11 ^ $f($b)($g); return another_function($a, $o); }
any thoughts or right direction more welcomed!
in general, works same:
function g($r) { return round($r / pow(10, round(m_log10e * log($r))) * 10); } function claculate($a, $b) { $o = ((g($a) % 2) || (g($a * $b) % 7 * 1 / 7) || 11) ^ g($b); }
the first problem in difference when evaluating or statement. (js returns number, php bool.) can solved using of conditions.
the worst js uses 2 more digits real numbers.
Comments
Post a Comment