Last active
February 23, 2023 18:15
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function simpleMultiplication(number) { | |
return number * (number % 2 > 0 ? 9 : 8) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function simpleMultiplication($number) | |
{ | |
return $number % 2 > 0 ? $number * 9 : $number * 8; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simple_multiplication(number) : | |
return 9*number if number % 2 > 0 else 8*number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Making use of modulo in the 3 languages and ternary operator (
?
) in PHP and Javascript.