Several corrections to JS syntax #2

wants to merge 10 commits into


None yet
2 participants

MattiSG commented Mar 12, 2012

No description provided.

You need tilda operator to convert -1, which indexOf returns if text is not found to 0 and evaluate condition to false. Otherwise value will be other than zero, so condition will evaluate to true


MattiSG replied Mar 12, 2012

Oh, you're right, I went too quickly here :)

However, I would argue ~ is hardly common, and != -1 is much more usual. ~ sounds more like a trick ;)

The point was to show how to do this with an array, like ruby does.


MattiSG replied Mar 12, 2012

Oh, ok. Maybe you should use an intermediate variable then, like you did in other examples? :) It is not really clear otherwise, IMHO.

Good idea, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment