Implemented indexJ from homework 7.