Paste: counts values in seq

Author: randy7
Mode: factor
Date: Mon, 5 Jan 2009 09:04:37
Plain Text |
! similar to what "array_count_values" in php does.

: count-seq ( seq -- seq' ) dup '[ _ swap '[ _ = ] count ] map ; ! fry first, map second ... i think :)
: count-dups ( seq -- seq ) dup count-seq zip prune >array ;

Annotation: leave just duplicates

Author: randy7
Mode: factor
Date: Mon, 5 Jan 2009 09:15:35
Plain Text |
: just-2+ [ dup second  2 < [ drop f ] when  ] map harvest ;

! example:
! { "hi" "hi" "there" } count-dups just-2+ .

New Annotation

Summary:
Author:
Mode:
Body: