Solve this - Sajha Mobile
SAJHA MOBILE
Solve this
Posts 14 · Viewed 7300 · Likes 1 · Go to Last Post
A_GuY
· Snapshot 0
Like · Likedby · 0
Programming Puzzle - hot question asked in interview

http://www.gufgaaf.com/Page/DisplayThread?threadId=5
BadhiJanne
· Snapshot 75
Like · Liked by · 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
· Snapshot 96
Like · Liked by · 0
Yeah. But that prints 1 to 100 but we have to print 100 to 1.
A_GuY
· Snapshot 100
Like · Liked by · 0
try this as well -

http://gufgaaf.com/Page/DisplayThread?threadId=13
Pharsi
· Snapshot 140
Like · Liked by · 0
Set I to 101 and decrease I to 1 or something like that.
ghogay_moro
· Snapshot 217
Like · Liked by · 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
· Snapshot 260
Like · Liked by · 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
· Snapshot 290
Like · Liked by · 0
for(var i=0; i<100; i++) {
console.log(100-i);
}
A_GuY
· Snapshot 368
Like · Liked by · 0
c864916 - you got it.

ghogay_moro
· Snapshot 389
Like · Liked by · 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
· Snapshot 412
Like · Liked by · 0
This is super basic. Calling it a Puzzle, itself is a Puzzle. Lol.
c864916
· Snapshot 442
Like · Liked by · 1
@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
· Snapshot 480
Like · Liked by · 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
· Snapshot 508
Like · Liked by · 0
Thanks guys for participating..
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 2 · Viewed 217
· Posts 1 · Viewed 114
· Posts 11 · Viewed 1074 · Likes 1
· Posts 1 · Viewed 82
· Posts 1 · Viewed 87
· Posts 4 · Viewed 410
· Posts 9 · Viewed 1421
· Posts 1 · Viewed 131
· Posts 1 · Viewed 130
· Posts 1 · Viewed 94



Your Banner Here
Travel Partners
Travel House Nepal