add javascript functions for recursive problems