Basic machine algorithms in JavaScript (based on those described in Programming Collective Intelligence by Toby Segaran)