Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-14-2012, 04:19 PM   #1
gavra
Registered User
 
Join Date: Jun 2012
Posts: 10
Default Find the number of people that can be seen from the treasurer place of view.

can anyone help me with following
behind the treasury there is n people waiting in the row with their height h[1], h[2], h[3]...h[n]. Find the number of people that can be seen from the treasurer place of view.
example : heightes are 155,170,165,180,175,195 - the answer is 4 he can see 1st, 2nd,4th, 6th.
thank you..
gavra is offline   Reply With Quote
Old 06-14-2012, 05:44 PM   #2
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

ActionScript Code:
var people:Array = new Array(155,170,165,180,175,195); function countHigher(arr) {     var count = 0;     var tmp;     for (var i = 0; i<people.length; i++) {         (tmp>people[i]) ?  count: (tmp=people[i], count++);     }     return count; } trace("Count: "+countHigher(people));


__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 06-14-2012, 07:23 PM   #3
paulina
Senior Member
 
Join Date: Jan 2010
Posts: 116
Default

Hello!
Sorry to interrupt.
I have never seen such a function. Can someone please explain.
paulina is offline   Reply With Quote
Old 06-15-2012, 08:37 PM   #4
gavra
Registered User
 
Join Date: Jun 2012
Posts: 10
Default

thanks, but if you have some extra time can you explain to me what actually does " ? " and " : " in this line (tmp>people[i]) ? count: (tmp=people[i], count++);

Last edited by gavra; 06-15-2012 at 08:46 PM.
gavra is offline   Reply With Quote
Old 06-16-2012, 12:20 AM   #5
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

Code:
(condition) ? trueExpression : falseExpression
for example:

ActionScript Code:
(5>3) ? trace("yes") : trace("no");

If 5 is greater than 3, if that condition is TRUE, then execute the TRUE expression, which is to the left for " : ", but let's alter the code:

ActionScript Code:
(1>3) ? trace("yes") : trace("no");

in this case, 1 is NOT greater than 3, so the FALSE expression will be executed, which is to trace "no".
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 06-16-2012, 04:27 AM   #6
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

Prid explained all which you want to know.

Else, this is a shorthand of if..else statement.

Thank you Prid



__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 06-16-2012, 01:14 PM   #7
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

np

btw, gotta commend you for that great short code
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 06-16-2012, 02:12 PM   #8
gavra
Registered User
 
Join Date: Jun 2012
Posts: 10
Default

I just never used that kind of if statement before. Thanks
gavra is offline   Reply With Quote
Old 06-16-2012, 02:21 PM   #9
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

@gavra: trust me, when I first saw it, I thought it was some really complex code, but after discovering that it was a common programming syntax, I learned of its simplicity
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 06-16-2012, 05:11 PM   #10
gavra
Registered User
 
Join Date: Jun 2012
Posts: 10
Default

Quote:
Originally Posted by Prid View Post
@gavra: trust me, when I first saw it, I thought it was some really complex code, but after discovering that it was a common programming syntax, I learned of its simplicity
well said
gavra is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:41 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.