Skip to content

Conversation

@jillirami
Copy link

Binary and Decimal

Congratulations! You're submitting your assignment.

score += (2 ** (8 - (index + 1)))
end
end
# eight_decimals = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would delete the code that's commented out, since you're not using it. That way it's more readable and someone else won't accidentally uncomment something they shouldn't.


bin_array.each_with_index do |binary, index|
if binary == 1
score += (2 ** (8 - (index + 1)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love how the calculation is all on one line. Amazing. Also like how you used the index to decrease the exponent each time. 👌

Copy link

@shubha-rajan shubha-rajan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Just delete the commented out code and you're good! Also I'm not sure if we could use each_with_index on this assignment (idk where I heard that we couldn't) so if you want to redo this assignment in Hard Mode, try it with a while loop instead ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants