DEV Community

Discussion on: How to Build Binary to Decimal Converter Using JavaScript

Collapse
jonrandy profile image
Jon Randy • Edited

A shorter way to do the actual conversion (without using parseInt):

[...str].reverse().reduce((a,v,i)=>a+(+v?1<<i:0),0)
Enter fullscreen mode Exit fullscreen mode
Collapse
jonrandy profile image
Jon Randy • Edited

Or even:

[...str].reduce((a,v)=>+v+a*2,0)
Enter fullscreen mode Exit fullscreen mode