Class: Rubies::RandomArray

Inherits:
Array
  • Object
show all
Defined in:
lib/rubies/random_array.rb

Instance Method Summary collapse

Instance Method Details

#generateObject



19
20
21
22
# File 'lib/rubies/random_array.rb', line 19

def generate
  depth = rand(0..3)
  nesting_array.flatten(depth)
end

#mini_arrayObject



4
5
6
# File 'lib/rubies/random_array.rb', line 4

def mini_array
  (-1_000..1_000).sort_by { rand }.sample 3
end

#nesting_arrayObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/rubies/random_array.rb', line 8

def nesting_array
  result = []
  rand(1..3).times do
    result << mini_array
  end
  result.each do |array|
    array << self.mini_array
  end
  result
end