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.
17,148 Comments - Last post 3 minutes ago by pivotalHarry
384 Comments - Last post 20 minutes ago by GarlicToast
67 Comments - Last post 37 minutes ago by JonathanDoe
15 Comments - Last post 1 hour ago by Fluffster
4 Comments - Last post 1 hour ago by gameboy9725
512 Comments - Last post 1 hour ago by OldPup
211 Comments - Last post 3 hours ago by crocospect
10,835 Comments - Last post 1 minute ago by UraniumFalconPunch
30,533 Comments - Last post 1 minute ago by Yamaraus
318 Comments - Last post 4 minutes ago by xXShurraXx
97 Comments - Last post 4 minutes ago by Vin3
149 Comments - Last post 5 minutes ago by f300
643 Comments - Last post 6 minutes ago by Zolivv
1,226 Comments - Last post 11 minutes ago by Kyog
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.