Calculate the sum of two integers a and b, without using the operator + and -.

This should probably be solved using bitwise operators but here’s a quick solution using the sum method on arrays.

def get_sum(a, b)
[a,b].sum
end

We simply call the sum method on the numbers we are adding after turning them into an array.

Written by

Full-stack Engineer. Rails/Node.js/React. I love plantain chips! Reach me at Adebola.dev.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store