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: 8 additions & 4 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
function greet(name: string): void {
// Your code here
console.log("Hello " + name);
}

/**
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 == 1; // replace false with what you see is fit
}

/**
Expand All @@ -34,9 +34,12 @@ function isOdd(n: number): boolean {
* oddsSmallerThan(7) -> 3; // the odd numbers being 1, 3, 5
* oddsSmallerThan(15) -> 7; // the odd numbers being 1, 3, 5, 7, 9, 11, 13
*/

function oddsSmallerThan(n: number): number {
// Your code here

const half = n/2;
const answer = Math.floor(half);
return answer;
return -1; // replace -1 with what you see is fit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since we return before this line, the second return is a line that will never be reached. We can delete it.

}

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

if(isOdd(n)) return n * n;
else return n * 2
return -1; // replace -1 with what you see is fit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This line will never be reached. Delete it

}

Expand Down