Calculate tripcodes in JavaScript.