Port algorithm methods to JavaScript