DEV Community

Discussion on: [Challenge] Add numbers without (+-*/)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited
const add=(a,b,c)=>{for(;b;c=a&b,a=a^b,b=c<<1);return a}
Enter fullscreen mode Exit fullscreen mode

A bit shorter (if you don't mind polluting namespace):

const add=(a,b)=>{for(;b;c=a&b,a=a^b,b=c<<1);return a}
Enter fullscreen mode Exit fullscreen mode