Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
*/
function greet(name: string): void {
// Your code here
console.log(`Hello ${name}`);
}

/**
* isOdd(n):
* - Accepts a "n" parameter of type "number"
* - Accepts a "n" parameter of type "number"`
* - returns true if it's odd, false otherwise
*
* e.g.
Expand All @@ -21,8 +22,7 @@ function greet(name: string): void {
*/
function isOdd(n: number): boolean {
// Your code here

return false; // replace false with what you see is fit
return n % 2 !== 0 ? true : false; // replace false with what you see is fit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit the true and falst part and just do:

return n % 2 !== 0;

Since that is a boolean condition it will return the true or false.

}

/**
Expand All @@ -36,8 +36,7 @@ function isOdd(n: number): boolean {
*/
function oddsSmallerThan(n: number): number {
// Your code here

return -1; // replace -1 with what you see is fit
return Math.floor(n / 2); // replace -1 with what you see is fit
}

/**
Expand All @@ -52,8 +51,7 @@ function oddsSmallerThan(n: number): number {
*/
function squareOrDouble(n: number): number {
// Your code here

return -1; // replace -1 with what you see is fit
return n % 2 == 0 ? n * 2 : n * n; // replace -1 with what you see is fit
}

export { greet, isOdd, oddsSmallerThan, squareOrDouble };