Logo

Programming-Idioms

  • Python
  • JS
  • C++
int square(int x){
  return x*x;
}
def square(x):
    return x*x

You don't have to explicitly write the return type
def square(x):
    return x**2

You can use power operator
square = lambda x: x * x
function square(x) { 
	return x * x;
}
const square = (x) => x * x;
const square = (number) => Math.pow(number, 2);
const square = n => n**2

The exponentiation operator is the most expressive way to do this.
function Square (X : Integer) return Integer is
begin
   return X * X;
end Square;

New implementation...
< >
programming-idioms.org