Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #20413

Drop every nth

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Drop every nth
Date 2013-03-07 20:25 +0000
Organization A noiseless patient Spider
Message-ID <khat2u$50t$1@dont-email.me> (permalink)

Show all headers | View raw


P16 (**) Drop every N'th element from a list.
    Example:
    * (drop '(a b c d e f g h i j) 3)
    (A B D E G H J)


Factor:

USING: locals grouping sequences.deep ;

:: drop-nths ( seq n -- seq )
  seq n group
  [ dup length n 1 - min head ] map
  flatten
;
  

{ "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" }
3 drop-nths .
{ "a" "b" "d" "e" "g" "h" "j" }

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Drop every nth "WJ" <w_a_x_man@yahoo.com> - 2013-03-07 20:25 +0000

csiph-web