DEV Community

loading...

Discussion on: Interview question for a Senior Js Developer, pt 1 (Questions), updated with answers link.

Collapse
scottbromander profile image
Scott Bromander

You are correct. The case breaks because superman in the second case starts at the first position, array index 0.

You would have to do some other shifting as well to make a !== work. !str.toLowerCase().indexOf('superman') is technically false. So false !== -1 is actually true. But false !== 7 is also true. A good way to approach it if you wanted to use equality would be something like str.toLowerCase().indexOf('superman') === -1 ) for the condition.

But generally, I favor less characters, so something like:
if (str.toLowerCase().indexOf('superman') < 0).

But, as always, shred my solution! I love feedback. Only way to grow is to learn from others who are more right!