Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Drop top N items
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
DanMonroe  
View profile  
 More options Apr 21 2009, 8:10 pm
From: DanMonroe <danmonroe....@gmail.com>
Date: Tue, 21 Apr 2009 17:10:01 -0700 (PDT)
Local: Tues, Apr 21 2009 8:10 pm
Subject: Drop top N items
HI All,

Hopefully this is an easy question.

Given an unsorted list of numbers, I need to "drop" or disregard N
number of the highest numbers.  Then I need to print the list in
original order and show which numbers were dropped.

for example, given:

def myList = [ 5, 2, 7, 9, 7, 3, 1 ]
def highNumbersToDrop = 2

// I need to...

myList.each() { thisItem ->

   println thisItem

}

// having a result of something like:

5
2
7 - dropped
9 - dropped
7
3
1

My question is how to keep track of which numbers were "dropped" so
that when I display the list, I can add the " - dropped" text.

Thanks in advance,
Dan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adrian Powell  
View profile  
 More options Apr 22 2009, 1:27 pm
From: Adrian Powell <adrian.a.pow...@gmail.com>
Date: Wed, 22 Apr 2009 10:27:51 -0700
Local: Wed, Apr 22 2009 1:27 pm
Subject: Re: [groovyvan] Drop top N items

Sort the array, slice the numbers to drop and store in a separate list.
When you print the original list you can compare this to the newly created
"dropped" list.

myList.each{ println "$it" + (droppedList.contains(it) ? " - dropped" : "")

}

Something like that.

-Adrian


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google