After browsing through Rescript's API, it seems like there is no function that compares 2 strings that returns a boolean. The best option is localeCompare
but it behaves somewhat different from the JS's ==
. Why does localeCompare
return a float instead of an integer?
Comparing String in Rescript
357 Views Asked by heiheihang At
1
You can compare strings using
==
in rescript as well. Alternatively there is aString.equal
as well if you need a function restricted to strings specifically, The "native" (non-Js
) standard library modules such asString
unfortunately seems to be left out of the rescript documentation entirely.localeComapre
probably returns afloat
because it might be possible for it to return non-integer numbers. JavaScript unfortunately has no integer type, which makes it hard to know if it could returnfloat
s even if it seems obvious that it shouldn't. I've seen several of this kind of bugs myself in various bindings.