Good point! But if we skip join it won’t work quite right. Here’s why when we do n.toString(2).split('0'), it creates an array of parts separated by '0's... For example, 1234 in binary is 10011010010. Splitting by 0 gives us this [ '1', '', '11', '1', '', '1', '' ]. Now if we take the length here it counts the parts in the array, not just the '1s. So join('') is needed to merge it all back together before counting. But great observation.. definitely try it out yourself to see the difference... :)
Well explained!!
You can directly return the length of the array, don't have to use join to Marge the array and then return the length.
Good point! But if we skip join it won’t work quite right. Here’s why when we do n.toString(2).split('0'), it creates an array of parts separated by '0's... For example, 1234 in binary is 10011010010. Splitting by 0 gives us this [ '1', '', '11', '1', '', '1', '' ]. Now if we take the length here it counts the parts in the array, not just the '1s.
So join('') is needed to merge it all back together before counting. But great observation.. definitely try it out yourself to see the difference... :)
@@LogicLab_YT oh yeah I didn't think about the edge point, you're right they can be 11 or even 111,,, thanks
Pr esa krna ku h 😢