Basic algorithms implemented in JavaScript