Algorithm examples in JavaScript