[VIEWED 8510
TIMES]
|
SAVE! for ease of future access.
|
|
|
A_GuY.
Please log in to subscribe to A_GuY's postings.
Posted on 06-15-16 9:06
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Programming Puzzle - hot question asked in interview http://www.gufgaaf.com/Page/DisplayThread?threadId=5
|
|
|
|
BadhiJanne
Please log in to subscribe to BadhiJanne's postings.
Posted on 06-15-16 9:50
PM [Snapshot: 75]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Easily can be done since modifying for loop is allowed. Just have i<101 and increase i by i=i+1 and print i. But this can be done without modifying the For loop. Just print ("1","2","3"......."100"); :)
|
|
|
A_GuY.
Please log in to subscribe to A_GuY's postings.
Posted on 06-15-16 10:14
PM [Snapshot: 96]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Yeah. But that prints 1 to 100 but we have to print 100 to 1.
|
|
|
A_GuY.
Please log in to subscribe to A_GuY's postings.
Posted on 06-15-16 10:15
PM [Snapshot: 100]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
try this as well - http://gufgaaf.com/Page/DisplayThread?threadId=13
|
|
|
Pharsi
Please log in to subscribe to Pharsi's postings.
Posted on 06-15-16 11:04
PM [Snapshot: 140]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Set I to 101 and decrease I to 1 or something like that.
|
|
|
ghogay_moro
Please log in to subscribe to ghogay_moro's postings.
Posted on 06-16-16 5:58
AM [Snapshot: 217]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
i'd do this in scripting for similar needs - I think the question asked to print 100 to 1: for(i=100; i>0; i--) { console.log(i); } and if you wanted 1 to 100: for(i=1; i<101; i++) { console.log(i); } wish all interview questions were as lame.
|
|
|
A_GuY.
Please log in to subscribe to A_GuY's postings.
Posted on 06-16-16 7:21
AM [Snapshot: 260]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
@ghogay_moro Oops thats wrong.- everything needs to be done within for(var i=0){ } you cant start another for loop outside closing parenthesis. and you can't print 1 to 100.
|
|
|
c864916
Please log in to subscribe to c864916's postings.
Posted on 06-16-16 7:43
AM [Snapshot: 290]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
for(var i=0; i<100; i++) { console.log(100-i); }
|
|
|
A_GuY.
Please log in to subscribe to A_GuY's postings.
Posted on 06-16-16 9:26
AM [Snapshot: 368]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
|
|
|
ghogay_moro
Please log in to subscribe to ghogay_moro's postings.
Posted on 06-16-16 9:46
AM [Snapshot: 389]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
a_guy, i think i am not seeing the obvious. care to explain a bit how my for loop is "starting" outside either parentheses? not trying to be a deek, but just trying to understand which part of the question i misread. cheers!
Last edited: 16-Jun-16 09:47 AM
|
|
|
fuckeetow
Please log in to subscribe to fuckeetow's postings.
Posted on 06-16-16 9:58
AM [Snapshot: 412]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
This is super basic. Calling it a Puzzle, itself is a Puzzle. Lol.
|
|
|
c864916
Please log in to subscribe to c864916's postings.
Posted on 06-16-16 10:27
AM [Snapshot: 442]
Reply
[Subscribe]
|
Login in to Rate this Post:
1
?
Liked by
|
|
@ghogay_moro: What I understood was that the initializer expression should be limited to var i = 0. @A_GuY: Correct me if I am wrong. @fuckeetow: Yes, it's pretty straightforward. The only confusion folks had was with the initializer constraint.
|
|
|
ghogay_moro
Please log in to subscribe to ghogay_moro's postings.
Posted on 06-16-16 11:01
AM [Snapshot: 480]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
thanks c88.., for the explanation. i can now wrap that in my head. the original question should have asked just that! side note: talking about interviews, i once helped prepare a question for an interview - to come up with a typewriter effect via ActionScript (Flash was a thing then!), and he didn't waste more than 3 minutes to complete it. it takes me more than 3 minutes to just think through the problem. some people really are good at what they do!
|
|
|
A_GuY.
Please log in to subscribe to A_GuY's postings.
Posted on 06-16-16 11:26
AM [Snapshot: 508]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Thanks guys for participating..
|
|
|