Factorisation example written in JavaScript