I've never tried Scala but you could just do this in 8 lines of Java and keep it readable and familiar:
public static int loveMatch(String name1, String name2, String compWord) {
int [] tally = new int[compWord.length()];
for (char c : (name1 + name2).toCharArray())
for (int t = 0; t < tally.length; t++)
if (c == compWord.charAt(t)) tally[t]++;
for (int i = tally.length - 1; i >= 0; i--)
for (int j = 0; j < i; j++)
tally[j] += tally[j + 1];
return tally[0] * 2;
}
...and the author shouldn't blame Java for his implementation not supporting "is"... what's that all about? |