add js recursive function