Skip to content
Advertisement

Function recursion advice

I am building an employee tracking app. I want my app to work so that after each one of the functions for the various list selections is complete, the app will re-prompt you with the options list again. There are a few methods I can think of to achieve this but I was hoping a more seasoned developer could recommend which method is the best. Thanks!

  1. make all the functions in the switch statements into promises and then make a promise chain that recalls itself
  2. try and use async-await instead of a promise chain???
  3. export the prompt() function and import it and all the other corresponding functions in each lib file

here is the entry point of the app

JavaScript

Advertisement

Answer

I think the switch statement is overkill. If you create an object where the key is the option and the function is the value then it is a 1:1 lookup and hypothetically more performant.

Additionally, drop the then statements because we write modern code here. Also congrats on the internship.

JavaScript

I can answer any questions in the comment section. Thanks!

Advertisement