From 0d8aacb907fc438f7580c154db30143e6028b750 Mon Sep 17 00:00:00 2001 From: Kiera Date: Sun, 25 Feb 2018 17:52:20 -0800 Subject: [PATCH] completed binary to decimal method, confirmed passing tests --- lib/binary_to_decimal.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/binary_to_decimal.rb b/lib/binary_to_decimal.rb index 439e8c6..3b26fea 100644 --- a/lib/binary_to_decimal.rb +++ b/lib/binary_to_decimal.rb @@ -5,5 +5,15 @@ # Calculate and return the decimal value for this binary number using # the algorithm you devised in class. def binary_to_decimal(binary_array) + length = binary_array.length + new_array = binary_array.reverse + decimal = [] + i = 0 + length.times do + decimal << new_array[i] * 2 ** i + i += 1 + end + return decimal.reduce(0, :+) raise NotImplementedError end +# comment