06-14-2012, 04:19 PM
|
#1
|
|
Registered User
Join Date: Jun 2012
Posts: 10
|
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..
|
|
|
06-14-2012, 05:44 PM
|
#2
|
|
Senior Member
Join Date: Jan 2011
Posts: 699
|
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
|
|
|
06-14-2012, 07:23 PM
|
#3
|
|
Senior Member
Join Date: Jan 2010
Posts: 116
|
Hello!
Sorry to interrupt.
I have never seen such a function. Can someone please explain.
|
|
|
06-15-2012, 08:37 PM
|
#4
|
|
Registered User
Join Date: Jun 2012
Posts: 10
|
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.
|
|
|
06-16-2012, 12:20 AM
|
#5
|
|
Prid - Outing
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,157
|
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".
__________________
17 Years old boy, who loves the Computer Technology
|
|
|
06-16-2012, 04:27 AM
|
#6
|
|
Senior Member
Join Date: Jan 2011
Posts: 699
|
Prid explained all which you want to know.
Else, this is a shorthand of if..else statement.
Thank you Prid
__________________
Regards
arkitx
|
|
|
06-16-2012, 01:14 PM
|
#7
|
|
Prid - Outing
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,157
|
np
btw, gotta commend you for that great short code
__________________
17 Years old boy, who loves the Computer Technology
|
|
|
06-16-2012, 02:12 PM
|
#8
|
|
Registered User
Join Date: Jun 2012
Posts: 10
|
I just never used that kind of if statement before. Thanks
|
|
|
06-16-2012, 02:21 PM
|
#9
|
|
Prid - Outing
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,157
|
@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
__________________
17 Years old boy, who loves the Computer Technology
|
|
|
06-16-2012, 05:11 PM
|
#10
|
|
Registered User
Join Date: Jun 2012
Posts: 10
|
Quote:
Originally Posted by Prid
@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
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 04:54 AM.
///
|
|