With a single =? It functions as an assignment. if(i=14) { } attempts to assign 14 to the variable i, which should always return true, so the code in the conditional block will always run. The code…
if(i=14) {z[1]=c[i]}
…will always be equivalent to…
i = 14;
z[1] = c[14];
Comment has been collapsed.
xdem and vonPreusen are correct as well, so you might want to update your code further to reflect what they said, you want double equal signs, not single (or triple equal signs, but double is probably what you want). single equal sign is always an assignment statement, and in most languages USUALLY evaluates to true (although if you assign something the value 0, in many langauges 0 == false, likewise assigned a variable a boolean value of false will also make the assignment evaluate to false).
also if you're having problems using ternaries, then I wouldn't use them. they are "fast and dirty", they don't make the code any faster and when you nest them like you do they are much harder to read, at least try spacing them out line by line like thus (if you insist on using them):
i == 47 ? z[0] = c[i] :
( i == 14 ? z[1] = c[i] :
( i == 52 ? z[2] = c[i] : z[3] = c[i] ) );
p.s. you also have too many colons and not enough ?'s in your line of ternary operators.
Likewise don't write things like z[4]=z[3]=z[0];, that's not good style, especially since different languages may treat the order of assignment differently, (so someone reading this line not accustomed to JS may not know whether it's l-to-r or r-to-l) be explicit and write it in two lines.
Comment has been collapsed.
for(var i=0;i < c.length;++i){
i=47?z[0]=c[i]:(i=14:z[1]=c[i]:i=52:z[2]=c[i]:z[3]=c[i]);
z[3]=z[4]=z[0]; }
You should have a closer look here... Hint: What happens with i?
Comment has been collapsed.
You know that ternaries are two answer structures, right?
ex: age == 10 ? PossibleResult1 : PossibleResult2;
Whenever you want another ternary, you have to follow the same structure:
So PossibleResult 2 would be something like: age == 15 ? PossibleResult3 : PossibleResult4
Leading to: age == 10 ? PossibleResult1 : age == 15 ? PossibleResult3 : PossibleResult4
So, for a more 'complex' one, it would look like this:
age == 10 ? PossibleResult1 : age == 15 ? PossibleResult3 : age >= 50 ? age <= 30 ? PossibleResult 5 : PossibleResult6
but you should read like this:
age == 10 ? (PossibleResult1) : (age == 15 ? PossibleResult3 : (age >= 50 ? (age <= 30 ? PossibleResult 5) : PossibleResult6))
Comment has been collapsed.
In the function glcvii.r() you're modifying the loop counter i from inside the loop. That's likely to create the exact sort of problem you're having.
I'm surprised it ran at all, though, because the expression i=14:z[1]=c[i]:i=52:z[2]=c[i]:z[3]=c[i] shouldn't even parse.
Comment has been collapsed.
ternaries. but everything else you listed works too. + would it kill you to have readable variables instead of having one letter variables.
those all are little things but changing them would make it easier, not important that it's "faster" or smth, you're script is too small to make any difference in any matter
Comment has been collapsed.
There are quite a few changes that you could make here to speed up the function. For example, pretty much everything in the f function is f'd up. Heheheh. Also, the loop in r is unneeded if you're going to assign each element in the array individually like that. Rereading the title of the thread might help understand the problem here.
Comment has been collapsed.
812 Comments - Last post 15 minutes ago by PicoMan
30 Comments - Last post 16 minutes ago by IAMERROR404
315 Comments - Last post 24 minutes ago by MeguminShiro
2,046 Comments - Last post 2 hours ago by Gamy7
35 Comments - Last post 3 hours ago by Sunshyn
163 Comments - Last post 8 hours ago by WangKerr
1,533 Comments - Last post 13 hours ago by Whoosh
25 Comments - Last post 17 seconds ago by Fluffster
701 Comments - Last post 3 minutes ago by Fluffster
23 Comments - Last post 10 minutes ago by antidaz
496 Comments - Last post 13 minutes ago by LastM
838 Comments - Last post 15 minutes ago by Thexder
195 Comments - Last post 23 minutes ago by mdpeters
91 Comments - Last post 28 minutes ago by Sh4dowKill
Whenever I run this, it crashes my browser. Can you help?
var glcvii = {};
glcvii.f= function(){
var cArr = []
,b=31
,e=58
,y=(new Date).getFullYear()+1
,s='String'
,f='from'
,a=0;
for (var i=y/b; i < y/b+e; ++i){
cArr.push(eval(s+'.'+f+'CharCode(i)'));
};
return cArr;
}
glcvii.r = function(){
var c=glcvii.f()
, z=[];
for(var i=0;i < c.length;++i){
i=47?z[0]=c[i]:(i=14:z[1]=c[i]:i=52:z[2]=c[i]:z[3]=c[i]);
z[3]=z[4]=z[0];
}
return z.join('');
}
Comment has been collapsed.