Closed threepointone closed 6 years ago
I'm working on it :D
Heh I took a stab at it too, was my first attempt azt writing any Reason code... looks like we came up with similar implementations @thangngoc89! I didn't add the rei or tests tho - still figuring it all out.
@subpopular ha. Nice attempt ! It's basically 1:1 map with the original JS code. But I want to use Reason stdlib only so I avoided using Js.*
P/s: Isn't number * Math.sign(number)
=== Math.abs(number)
?
@thangngoc89 Interesting...I'm on like day 2 of Reason so this is good for me : ) One question though...
let newX = float_of_int(x^) /. 62. |> floor |> int_of_float;
Why use float just to use floor then back to int? Doesn't x / 62
return a floored int?
Also, good point on the abs
and keeping with the stdlib. TIL.
Ah. good point!. My rtop is currently broken so too lazy to check that. But isn't too magic ?
Seems expected that an int / int would return an int (always been my experience, though not in JS) - but again - everything is magic to me at this point heh :)
Yeah. I created a simple check at (DON"T OPEN IF YOU'RE ON MOBILE) https://reasonml.github.io/try/?reason=DYUwLgBAdiDuAaEC8EAUAPAlMgfBA3gFAQToQD0EAbAEwDchAvg4aJDAjcmlrgcRABmwAPYBDMAH0RgyQEsoYDNnIA6ajXUAfPMJEiAThB0QFUmZL0S6EJi0GG0c01AgAGCGBEQAjG-8B2EQkcoJoHPCoctgAhCgRNFGYQQIkAFIAzqqiAOZJAox2hJnZInkARAAmIjDlmEA
It's a loop from 0 to 1 milion to compare result between the 2 methods. And you're totally right. But it still feels like magic to me. I call that smart code
Slightly different approach with advice from @thangngoc89 https://github.com/threepointone/bs-nice/pull/7
:) what a happy problem to have. what should I do here, I can't accept both clearly :/
@threepointone benchmark !
I must admit, the second approach by @subpopular is more clever. But JIT can optimize a while loop better than a recursive function
just going to pick the one that looked simpler to me. thank you to the both of you for the effort!
currently uses bs.raw to inline javascript.