Some funny algorithms in javascript