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 isEvenNumber(int number) returns boolean { | |
// checks whether the `number` is divisible by `2` | |
if number % 2 == 0 { | |
return true; | |
} else { | |
return false; | |
} | |
} |
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
enum Grade { | |
A, B, C, F | |
} | |
function calculateGrade(int marks) returns Grade { | |
// checks whether the `marks` are greater than or equal to `75` | |
if marks >= 75 { | |
return A; | |
// checks whether the `marks` are less than `75` but greater than or equal to `65` | |
} else if marks >= 65 { |
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 isNumber(any value) returns boolean { | |
// checks whether the provided value is an `int` or a `float` | |
if value is int || value is float { | |
return true; | |
} | |
return false; | |
} |
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 isString(any value) returns boolean { | |
// checks whether the provided value is not a `string` | |
if value !is string { | |
return false; | |
} | |
return true; | |
} |
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 dayOfTheWeek(int date) returns string { | |
match date { | |
1 => { | |
return "Monday"; | |
} | |
2 => { | |
return "Tuesday"; | |
} | |
3 => { | |
return "WednesDay"; |
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 isDivisibleByFive(int number) returns string { | |
int lastDigit = number / 10; | |
match lastDigit { | |
// check whether last digit is `0` or `5` | |
0|5 => { | |
return "Divisible by Five"; | |
} | |
_ => { | |
return "Not Divisible by Five"; | |
} |
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 sum(int[] values) returns int { | |
int sum = 0; | |
// each iteration returns a value in the `array` | |
foreach int value in values { | |
sum += value; | |
} | |
return sum; | |
} |
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 factorial(int n) returns int { | |
int result = 1; | |
// iterates over values starting from `1` to `n` | |
foreach int value in 1..< n+1 { | |
result *= value; | |
} | |
return result; | |
} |
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 printEvenNumbersInRange(int range) { | |
int n = 1; | |
// run this loop until `n` is greater than or equal to `range` value | |
while n < range { | |
if n % 2 == 0 { | |
io:println(n); | |
} | |
} | |
} |
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 leastCommonMultiple(int a, int b) returns int { | |
int counter = 1; | |
while true { | |
counter += 1; | |
// if the `counter` is divisible by `a` and `b` break the loop | |
if counter % a == 0 && counter % b == 0 { | |
break; | |
} | |
} | |
return counter; |
OlderNewer