Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't understand the choices function in the example #2

Open
ctataryn opened this issue Nov 13, 2017 · 0 comments
Open

Don't understand the choices function in the example #2

ctataryn opened this issue Nov 13, 2017 · 0 comments

Comments

@ctataryn
Copy link

ctataryn commented Nov 13, 2017

In your example you have the following for the thirdQuestion:

  choices: answers => index => {
    switch (index) {
      case 0:
        return ['second line when selected first', 'third line when selected first'];
      case 1:
        return ['first line when selected second', 'third line when selected second'];
      case 2:
        return ['first line when selected third', 'second line when selected third'];
      default:
        return ['first line', 'second line'];
    }
  },

The inquirer documentation for the choices property of a question states:

choices: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers.

So in your example I understand using the short-form arrow (=>) is used to declare a function that takes an answers parameter, however I don't understand the second arrow (=>index). To me this almost looks as if it's a short-form for apply on an array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant