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

/**
Expand All @@ -20,9 +20,9 @@ function greet(name: string): void {
* isOdd(10) -> false
*/
function isOdd(n: number): boolean {
// Your code here
return n % 2 != 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Watch out for !=. We should use !==


return false; // replace false with what you see is fit
// replace false with what you see is fit
}

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

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

/**
Expand All @@ -51,9 +49,8 @@ function oddsSmallerThan(n: number): number {
* squareOrDouble(9) -> 81; // (9 ^ 2)
*/
function squareOrDouble(n: number): number {
// Your code here

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

Choose a reason for hiding this comment

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

Here we should use ===

else return n ** 2; // replace -1 with what you see is fit
}

export { greet, isOdd, oddsSmallerThan, squareOrDouble };