rewrite wordarray with scala