written code to duplicate inject method in class Array