Compare ZIP codes, disregarding leading zeros
The title of your post is


  Compare ZIP codes, disregarding leading zeros


The solution is simple -- just drop the leading zeros.  Then you can compare the strings directly.

This leads us to something like this:

def compareZip(first: String, second: String): Boolean = {
  first.dropWhile(c =&gt; c == '0') == second.dropWhile(c =&gt; c =='0')
}


If you want, you can factor out the common lambdas.

There's no need to do anything more complicated than that.  "Fixing" the zipcode only makes things more complicated.  And, since the result never leaves the comparison function anyway, all that work is wasted.