Skip to content

Instantly share code, notes, and snippets.

@brianbirir
Last active February 23, 2023 18:15
Show Gist options
  • Save brianbirir/8bb0c6ab20f906ed735a4234454419f5 to your computer and use it in GitHub Desktop.
Save brianbirir/8bb0c6ab20f906ed735a4234454419f5 to your computer and use it in GitHub Desktop.
Multiplying a given number by eight if it is an even number and by nine otherwise (Python, PHP and Javascript implementations)
function simpleMultiplication(number) {
return number * (number % 2 > 0 ? 9 : 8)
}
<?php
function simpleMultiplication($number)
{
return $number % 2 > 0 ? $number * 9 : $number * 8;
}
def simple_multiplication(number) :
return 9*number if number % 2 > 0 else 8*number
@brianbirir
Copy link
Author

Making use of modulo in the 3 languages and ternary operator (?) in PHP and Javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment