Функция:
public float simpleSimilarity(String u, String v) {
String[] a = u.split(" ");
String[] b = v.split(" ");
long correct = 0;
int minLen = Math.min(a.length, b.length);
for (int i = 0; i < minLen; i++) {
String aa = a[i];
String bb = b[i];
int minWordLength = Math.min(aa.length(), bb.length());
for (int j = 0; j < minWordLength; j++) {
if (aa.charAt(j) == bb.charAt(j)) {
correct++;
}
}
}
return (float) (((double) correct) / Math.max(u.length(), v.length()));
}
Тест:
String a = "This is the first string.";
String b = "this is not 1st string!";
// for exact string comparison, use .equals
boolean exact = a.equals(b);
// For similarity check, there are libraries for this
// Here I'll try a simple example I wrote
float similarity = simple_similarity(a,b);
Я думаю, что одна ошибка в том, что вам нужно изменить
<script src="https://maps.googleapis.com/maps/api/js?key=MYKEY&callback=initMap" async defer></script>
на
<script src="https://maps.googleapis.com/maps/api/js?key=MYKEY&callback=initialize" async defer></script>
, у вас нет функции initMap, но я предполагаю, что вы хотите Вызовите initialize ().
См. https://medium.com/@nikjohn/speed-up-google-maps-and-everything-else-with-async-defer-7b9814efb2b .
Проблема в том, что ваш файл js не загружается асинхронно, поэтому он выполняется до того, как скрипт Google Maps будет завершен.
Вам необходимо включить функцию обратного вызова, которую google
может вызывать после завершения загрузки.
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script>