Skip to content

Instantly share code, notes, and snippets.

@alexbrohman
alexbrohman / gist:614274128c9c00d0473523122af67975
Created May 15, 2019 21:20
Alex Brohman Javascript Coding Exemplar
# JavaScript Coding Exemplar:
### Question 1
The issue with the function is that when the string begins with 'superman', the indexOf is 0, which is a 'falsy' value. The if statement returns false for this 0 and because of this, the error is thrown.
The indexOf for a string without 'superman' is -1, so a better function in this case would be:
```
const validateString = (str) => {
if(str.toLowerCase().indexOf('superman') === -1)