Array.inject method rewritten using recursion