Couldn't I use the startsWith method?

I found another solution for me - is this also correct? Or did I understood the task wrong? Wasn’t the task about to find the index of the first animal which starts with a “s”.

const startsWithS = animals.findIndex(animal => { return animal.startsWith('s'); })

The output will be “3”.

That would depend upon a couple of factors…

  • Has the startsWith method been already introduced in the course?
  • Will the SCT expect it? If not, it shouldn’t be used in a solution.
  • Are you convinced that you could arrive at a solution that does not use the startsWith method?

The thing to always bear in mind is that learning a new approach does not mean we should discard older ones. If anything it should induce us to write naive methods that perform the same task.

1 Like

I already used the documentation, so I skipped the “older ones”. But of course you are right - it is good to be aware of that. Thx.

1 Like