I'm working on a multi platform app and I've finished the database and the web version. To check a code on the web version I get a hashed version from the database and compare the two. I use this javascript code to hash (I found this on another question):
hashCode = function(s){
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
}
Now I need to do the same in my android app, but I don't know how to make a function that outputs the same in java or kotlin. Does anyone know how to do this or have an other cross-platform vanilla solution?
Thanks in advance.
Edit: I'm very new to kotlin/java so I only know what I can find online and what I know about other languages. I tried to remove as much errors as possible but some things I just don't know, it still gives errors:
fun go (a: Int, b: String): Int {
var a = ((a shl 5) - a) + Character.codePointAt(b,0);
return a and a
} // this part doesn't give any errors now.
fun hashCode(s: String): String {
return s.split("").reduce(go(a,b)) // I don't know what to pass as parameters + reduce gives an error
}