Added JS middleEarth function and tests