Update factorial.js

Updated isPrime to be more efficient