He's another (longer) way
(vec (filter identity
(map
(fn [x idx] (if (zero? (mod 3 idx)) x))
[2 4 5 8 6 4]
(iterate inc 0))))
I'd use a form of partition production, though. Some thing like this:
(apply concat (partition-all 2 3 [2 4 5 8 6 4]))
The concat should be faster than flatten, because it doesn't have to
do a seqable? check.
Sean
On Dec 3, 12:42 pm, Mark N <[email protected]> wrote:
> You might want to use partition-all from seq-utils, since partition
> may drop the end elements if it can't make a full size partition.
>
> For example
> user=> (flatten (partition 2 3 [2 4 5 8]))
> (2 4)
>
> But
> user=> (flatten (partition-all 2 3 [2 4 5 8]))
> (2 4 8)
>
> On Dec 1, 9:31 pm, Wilson MacGyver <[email protected]> wrote:
>
> > you can do it using partition and flatten from clojure.contrib.seq-utils
>
> > (use 'clojure.contrib.seq-utils)
> > (flatten (partition 2 3 [2 4 5 8 6 4]))
>
> > this yields (2 4 8 6)
>
> > On Tue, Dec 1, 2009 at 10:06 PM, Don <[email protected]> wrote:
> > > I have a vector [2 4 5 8 6 4]
>
> > > And I want to remove a value based on index. Specifically, I want to
> > > remove every third item.
>
> > > So my new vector would be [2 4 8 6]
>
> > > Thank you.
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to [email protected]
> > > Note that posts from new members are moderated - please be patient with
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en
>
> > --
> > Omnem crede diem tibi diluxisse supremum.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en