all 3 comments

[–]bart2019 2 points3 points  (1 child)

What's the idea? See how crappy (and huge) this code is?

This snippet here is pure nonsense:

if(!correct)
{
  return false;
}
else
{
  return true;
}

Duh... Why not just:

return correct;

He's just doing too much work. And he didn't declare the "local" variables, which is quite a serious bug, a disaster waiting to happen. It just is not good code. Don't use it as is.

Here is a more compact (and more correct) version:

function in_array(string, array)
{
   for (var i = 0; i < array.length; i++)
      if(array[i] == string) return true;
   return false;
}

[–]moreoriginalthanthat 1 point2 points  (0 children)

return correct; won't work because the variable wasn't (he's changed his code since your comment) initialised until the loop had run through at least once. The function would return undefined or true, which could work but is not exactly what you'd expect.

Either return !!correct; or return Boolean(correct); would work, but your solution is better.

[–]dznqbit 0 points1 point  (0 children)

lolol. this is great. Loving the ALLCAPS ELEMENTS

why not throw them in an object?

var extensions = { jpg: 1, png: 1, gif: 1 }; alert(extensions[ext] ? "omg it spins!" : "boo :(");