Common algorithms in JavaScript