added js version for prime