Skip to content

Commit fc82a2c

Browse files
Merge pull request #4 from kotp/generate-ayb-tests
Update all-your-base example to use more idiomatic ruby
2 parents a23949e + 0e96040 commit fc82a2c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

exercises/all-your-base/example.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ def self.convert(base_from, number_array, base_to)
1010
convert_from_canonical_base(number_in_canonical_base, base_to)
1111
end
1212

13-
private
13+
private_class_method
1414

1515
def self.invalid_inputs?(base_from, number_array, base_to)
16-
number_array.any?{ |number| number < 0 || number >= base_from } ||
16+
number_array.any? { |number| number < 0 || number >= base_from } ||
1717
base_from <= 1 || base_to <= 1
1818
end
1919

2020
def self.convert_to_canonical_base(number_array, base)
2121
total = 0
2222
number_array.reverse.each_with_index do |number, index|
23-
total += number * base ** index
23+
total += number * base**index
2424
end
2525
total
2626
end
2727

2828
def self.convert_from_canonical_base(number, base_to)
2929
result = []
3030
current_number = number
31-
while current_number >= base_to do
32-
result << current_number % base_to
33-
current_number = current_number / base_to
31+
while current_number >= base_to
32+
result << current_number % base_to
33+
current_number /= base_to
3434
end
3535
result << current_number % base_to
3636
result.reverse

0 commit comments

Comments
 (0)