funkr 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,11 +90,22 @@ class Array
90
90
  end
91
91
  end
92
92
 
93
- # Constitue des groupes de n éléments
93
+ # Constitue des groupes disjoints de n éléments au plus
94
94
  def groups_of(n)
95
95
  return [] if self.empty?
96
96
  [self.take(n)] + self.drop(n).groups_of(n)
97
97
  end
98
98
 
99
+ # constitue des groupes de n éléments exactement, décalés de 1
100
+ def sliding_groups_of(n)
101
+ return [] if self.size < n
102
+ [ self.take(n) ] + self.tail.sliding_groups_of(n)
103
+ end
104
+
105
+ # trouve l'index d'une séquence
106
+ def seq_index(seq)
107
+ self.sliding_groups_of(seq.size).index(seq)
108
+ end
109
+
99
110
 
100
111
  end
data/lib/funkr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Funkr
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/test/tests.rb CHANGED
@@ -80,3 +80,10 @@ puts([1,2,4,5,7,5,8,2,10].group_seq_by{|x| x % 2}.inspect)
80
80
 
81
81
  puts "\n> groups_of"
82
82
  puts([1,2,4,5,7,5,8,2,10].groups_of(4).inspect)
83
+
84
+ puts "\n> sliding_groups_of"
85
+ puts((1..10).to_a.sliding_groups_of(3).inspect)
86
+
87
+ puts "\n> seq_index (30)"
88
+ puts((0..100).to_a.seq_index([30,31,32]))
89
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funkr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Rivier
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-14 00:00:00 +01:00
18
+ date: 2011-03-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21