Some useful algorithms coded in JavaScript