Could someone kindly explain why this integer 3 turns into an array? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 10

Could someone kindly explain why this integer 3 turns into an array?

This is like a puzzle, pleasešŸ™ David George šŸ‰SHAROFšŸ‰šŸ‡ŗšŸ‡æ Kuba Siekierzyński https://code.sololearn.com/c3b1oKi8gVY0/?ref=app

9th Jul 2020, 4:17 PM
ProfOduolašŸ™šŸ‡³šŸ‡¬
ProfOduolašŸ™šŸ‡³šŸ‡¬ - avatar
2 Respostas
+ 8
It is part of the definition of the integer class in Ruby. See https://ruby-doc.org/core-2.4.1/Integer.html int[n] -> 0, 1 Bit Reference--Returns the +n+th bit in the binary representation of int, where int[0] is the least significant bit. The binary representation of 3 is 11, so a[0] is the least significant bit, i.e. 1, and a[1] is the second least significant bit, which is also 1 The rest is as per your comments in the source file
9th Jul 2020, 4:29 PM
George
+ 5
Thank you very much George šŸ™
9th Jul 2020, 4:31 PM
ProfOduolašŸ™šŸ‡³šŸ‡¬
ProfOduolašŸ™šŸ‡³šŸ‡¬ - avatar