Rewriting code for inject for arrays