...

View Full Version : how to shrink code ? sample:



BubikolRamios
01-02-2008, 09:11 AM
Realy annoyed by this code but cant do it any other way.
Was trying using ?:; but no success.
So: any suggestion how to do the same with much lesss code ?
Thanks.



result = checkNick(nick);
if (result !='')
{
alert(result);
return;
}

result = checkMail(email);
if (result !='')
{
alert(result);
return;
}

result = checkPwd(pwd1,pwd2);
if (result !='')
{
alert(result);
return;
}

arilia
01-02-2008, 09:26 AM
try this




result = checkNick(nick) || checkMail(email) || checkPwd(pwd1,pwd2);
if (result)
alert(result);

BubikolRamios
01-02-2008, 09:55 AM
nope, mybe this would work if return type would be boolean, but it is string.

arilia
01-02-2008, 10:07 AM
well, it works on strings too. I tested it on FF and on IE6.

But you can try this too


result = checkNick(nick)? checkNick(nick) :(checkMail(email)? checkMail(email): checkPwd(pwd1,pwd2));

Anyway what kind of error you get?

hemebond
01-03-2008, 04:15 AM
result = checkNick(nick) || checkMail(email) || checkPwd(pwd1,pwd2);
if (result)
alert(result);
Works for me.

Trinithis
01-03-2008, 05:42 AM
var a = [checkNick(nick), checkMail(email), checkPwd(pwd1, pwd2)];
for(var i = 0, n = a.length; i < n; ++i)
if(a[i].length == 0) {
alert(a[i]);
return;
}

rnd me
01-03-2008, 08:57 PM
nope, mybe this would work if return type would be boolean, but it is string.

strings are essentially booleans in javascript:

""==false
"false" == true
"0"==true
"anything but blank" == true

BubikolRamios
01-05-2008, 11:10 AM
thanks to all.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum